Problems opening file

edited December 2015 in Questions about Code

I want to store some settings in a file and then read them, but it seems Processing can't read the file. I try finding the error using IOException and getMessage() but this doesn't work. Here's the code snippet from the setup() method:

BufferedReader inputSettings;
 inputSettings = createReader("settings.txt");
 // Read settings
 String[] input=new String[2]; 
 input[0]="I"; input[1]="R";

 for(int i=0; i<2; i++) {
   try {
     input[i] = inputSettings.readLine();
   }
   catch (IOException e) {
     e.printStackTrace();
     input[i] = null;
     System.out.println("File not found: " + e.getMessage());
   }
   if(input[i]==null) {System.out.println("ERROR"); exit(); }
 }

I get the output "ERROR" but not the one from System.out.println("File not found: " + e.getMessage());. There is a file settings.txt in the same folder as the program with two lines written in it.

Any ideas?

Answers

  • Answer ✓

    Perhaps try to use loadStrings() instead. Simpler, anyway.

  • edited October 2013

    Thanks for the answer! However it doesn't work either; the string array is empty after using loadStrings(), so I guess it didn't find the file.

    By the way I'm using windows 7, and I tried putting a copy of the file in the data folder as well.

    EDIT: Forget the above, using loadStrings() works! Turns out by a stupid mistake the text file I put in the data folder was empty. Thanks!

    (PS: I can't get the strikethrough working for some reason)

Sign In or Register to comment.