Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to write to a .DAT file but doesn't seem to be doing anything?
    primarykey
    data
    text
    <p>I used this code in a different application to write a name and highscore onto the file for my game. Now i'm using this code to get a name and password from a .DAT file and be able to add a new user and password. Here's the .DAT file.</p> <pre><code>michael123 speaker123 katherine123 motor123 username password </code></pre> <p>Here's the code. Reading the file works fine but writing to it does nothing at all and i'm unsure why.</p> <pre><code>InputStream file; BufferedReader fileStream; FileWriter fileWriter; BufferedWriter fileWrite; String temp = ""; int users = 0; public void readUserInfo() throws IOException { try { file = Board.class.getResourceAsStream("users.DAT"); fileStream = new BufferedReader(new InputStreamReader(file)); } catch (Exception e) { System.out.println("File not found"); } for (int i = 0; i &lt; users; i++) { temp = fileStream.readLine(); Board.username[i] = temp.trim(); temp = fileStream.readLine(); Board.password[i] = temp.trim(); } //Close fileStream.close(); file.close(); } public void addUser() throws IOException { fileWriter = new FileWriter(Board.class.getResource("users.DAT").getFile(),true); fileWrite = new BufferedWriter(fileWriter); System.out.println("Users : " + users); //Skip already created users for (int i = 0; i &lt; users; i++) { fileWrite.newLine(); fileWrite.append(Board.username[i]); fileWrite.newLine(); fileWrite.append(Board.password[i]); } System.out.println("Adding" + Board.username[users] + " : " + Board.password[users]); //Add user fileWrite.newLine(); fileWrite.append(Board.username[users]); fileWrite.newLine(); fileWrite.append(Board.password[users]); //Close fileWrite.close(); System.out.println("Closed fileWrite"); } </code></pre> <p>I'm using netbeans. The file being read from is in the same package as all the other classes. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload