Writing to file
Go to solution
Solved by Tech N Gamer,
Okay, after a ton of yawns and being drowsy, I've figured it out, I think. I think it's because Eclipse made it say
System.clearProperties("user.home")
instead of
System.getProperties("user.home")
. Here is the new code if anyone want's to see it:
private void checker() { String dirPath = System.getProperty("user.home") + "\\AppData\\Roaming\\ClassMaker"; String filePath = System.getProperty("user.home") + "\\AppData\\Roaming\\ClassMaker\\settings.ini"; System.out.println(dirPath + "\n" + filePath); if (System.getProperty("os.name").equals("Windows 10")) { if (new File(dirPath).exists()) { if (new File(filePath).exists()) { try { Scanner fileOpener = new Scanner(new File(filePath)); String line = fileOpener.nextLine(); String[] varibles = line.split("="); if (varibles[1].equals("true")) { alreadyRan = true; } } catch (FileNotFoundException e1) { JOptionPane.showMessageDialog(null, "An error has occured and the program failed to read a file." + "\nPlease send this error to the dev so he can figure out a fix.\n" + e1.toString(), "An Error has occured!", JOptionPane.ERROR_MESSAGE); System.exit(ABORT); } } else { createNewFile(filePath); } } else { if (!new File(dirPath).mkdir()) { JOptionPane.showMessageDialog(null, "An error has occured and the program failed to create a directory." + " The most likly cause of this is the program doesn't have proper" + "read and write permission.", "An Error has occured!", JOptionPane.ERROR_MESSAGE); System.exit(ABORT); } else { createNewFile(filePath); } } } } private void createNewFile(String path) { File file = new File(path); try { file.createNewFile(); } catch (IOException e) { JOptionPane.showMessageDialog(null, "An error has occured and the program failed to create a file." + "\nPlease send this error to the dev so he can figure out a fix.\n" + e.toString(), "An Error has occured!", JOptionPane.ERROR_MESSAGE); System.exit(ABORT); } try { PrintWriter printToFile = new PrintWriter(file.getAbsolutePath()); printToFile.print("alreadyRan=true"); printToFile.close(); } catch (IOException e) { JOptionPane.showMessageDialog(null, "An error has occured and the program failed to read a file." + "\nPlease send this error to the dev so he can figure out a fix.\n" + e.toString(), "An Error has occured!", JOptionPane.ERROR_MESSAGE); System.exit(ABORT); } }
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now