June 5, 20205 yr 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, 20205 yr by Son Christmas
June 5, 20205 yr 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.
June 6, 20205 yr 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.
Create an account or sign in to comment