Son Christmas Posted June 5, 2020 Share Posted June 5, 2020 (edited) When I try and write to a text file I get a permission error, Has anyone got working code for read/writing text files? My code: import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors import java.util.Scanner; // Import the Scanner class to read text files public class ReadFile { public static void main(String[] args) { try { File myObj = new File("filename.txt"); Scanner myReader = new Scanner(myObj); while (myReader.hasNextLine()) { String data = myReader.nextLine(); System.out.println(data); } myReader.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); } } } Edited June 5, 2020 by Son Christmas Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted June 5, 2020 Share Posted June 5, 2020 OSBot has certain security restrictions, such as the fact that you can't read or write files outside the OSBot Data folder (C:\Users\YourName\OSBot\Data). Try the code inside this folder, it should probably work. 1 Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted June 6, 2020 Share Posted June 6, 2020 You can use getDirectoryData() method to retrieve the path to the data folder, so that if you, or someone else has a different install location it will retrieve the correct path. 1 Quote Link to comment Share on other sites More sharing options...