althtu 0 Share Posted April 23, 2022 When I'm just compiling and building a project in IntelliJ I can add a text file to my Project and then access it at the following path Path inputDataPath = Paths.get("src","ItemIds.txt"); System.out.println(inputDataPath.toString()); But when I try accessing at that path for my bot script (which also has the file) I end up with a FileNotFoundException. java.io.FileNotFoundException: src\ItemIds.txt (The system cannot find the path specified) So, my question is - How can I add and access a data file from my bot scripts? Link to comment Share on other sites More sharing options...
althtu 0 Author Share Posted April 23, 2022 Just to clarify, I just want the path to the data file. I'm thinking it could be the following Paths.get(System.getProperty("user.dir"),"Scripts","MyScriptName","ItemIds.txt") which assumes you can get into MyScriptName.jar by Scripts/MyScriptName/ItemIds.txt. Link to comment Share on other sites More sharing options...
althtu 0 Author Share Posted April 23, 2022 After a bit of looking around, I found a good answer on StackOverflow. You can add the file to your project as normal but because its being built as a jar file you can't just read it like a regular text file. Based on Drew MacInnis' post on Stackoverflow, I was able to read the .txt file as follows: public List<Integer> readJarResource(String filename) { List<Integer> itemIds = new ArrayList<>(); try (InputStream in = getClass().getResourceAsStream(filename); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { while (reader.ready()) { String data = reader.readLine(); itemIds.add(Integer.parseInt(data)); } } catch (IOException e) { e.printStackTrace(); } System.out.println(itemIds); return itemIds; } Happy days. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.