Get json file in bukkit
php editor Youzi will help you quickly master the method of obtaining json files in bukkit. When developing Minecraft plug-ins using Java, manipulating json files is a common requirement. This article will introduce in detail how to obtain and parse json files in the bukkit plug-in, allowing you to easily cope with various development scenarios. Whether you are a novice or an experienced developer, you can benefit from it and quickly improve your technical level. Next, let’s dive into this issue and explore solutions.
Question content
I'm trying to get json in my plugin but it doesn't work. This is my code to get it, this is the path: static file json = new file("config.json");
. I tried using getdatafoder() method but couldn't because I am using static method.
public class JSONReader extends JavaPlugin { static File json = new File("config.JSON"); static File getJSON() { return json; } static JSONObject setupJson() { try { JSONParser jsonParser = new JSONParser(); Object parsed = jsonParser.parse(new FileReader(json.getPath())); JSONObject jsonObject = (JSONObject) parsed; return jsonObject; } catch (ParseException | IOException e) { return null; } } }
Workaround
All paths are evaluated relative to your working directory, which contains your server executable. bukkit provides convenient file access methods through JavaPlugin
:
Refer to files in the plug-in data folder
file f = new file(getdatafolder(), "config.json");
Copy after loginRetrieve files in the plug-in jar
InputStream is = getResource("config.json");
Copy after loginThe path is relative to the bukkit server jar, so from there you need to go to the file
/plugins/plugin-name/config.json
The above is the detailed content of Get json file in bukkit. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

