Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Personally, I think Object serialization is over kill in this situation.</p> <p>You could simply write the details to a text file...</p> <pre><code>public TestFileIO() { try { writeUser(new File("User.inf"), "Test", "Password".toCharArray()); } catch (IOException ex) { ex.printStackTrace(); } } public void writeUser(File file, String name, char[] password) throws IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file)); bw.write(name); bw.newLine(); bw.write(password); bw.flush(); } finally { try { bw.close(); } catch (Exception e) { } } } </code></pre> <p>This will simply write the user name and password to a file, separating each by a new line.</p> <p>If you need more then one user in the file, you could simple write the user name password on the same line, using a predefined delimiter...</p> <pre><code>public TestFileIO() { try { writeUser(new File("User.inf"), "Test", "Password".toCharArray()); } catch (IOException ex) { ex.printStackTrace(); } } public void writeUser(File file, String name, char[] password) throws IOException { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(file)); bw.write(name); bw.write(";"); bw.write(password); bw.flush(); } finally { try { bw.close(); } catch (Exception e) { } } } </code></pre> <p>Now, if you worried about saving the password as plain text, you could (and personally world) save the password as a MD5 hash...</p> <pre><code>public TestFileIO() { try { writeUser(new File("User.inf"), "Test", "Password".toCharArray()); } catch (Exception ex) { ex.printStackTrace(); } } public void writeUser(File file, String name, char[] password) throws IOException, NoSuchAlgorithmException { BufferedWriter bw = null; try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] bytes = new byte[password.length]; for (int i = 0; i &lt; bytes.length; i++) { bytes[i] = (byte) password[i]; } md.update(bytes); byte[] mdbytes = md.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i &lt; mdbytes.length; i++) { sb.append(Integer.toString((mdbytes[i] &amp; 0xff) + 0x100, 16).substring(1)); } bw = new BufferedWriter(new FileWriter(file)); bw.write(name); bw.newLine(); bw.write(sb.toString()); bw.flush(); } finally { try { bw.close(); } catch (Exception e) { } } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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