4 Replies Latest reply: Jun 22, 2008 11:01 PM by EJP RSS

    How to Write A Binary File.

    807601
      I am creating a program which will save data but i want this data to be encrypted/or unreadable.

      I have created a simple console application which reads users input changes it into bytes and saves it to a file.
      But its still saving it as readable text? any ideas?
                     Scanner in = new Scanner(System.in);
                     FileOutputStream fos;
                     
                     try
                     {
                          fos= new FileOutputStream(new File("data.txt"));
                                         
                          System.out.print("Enter String: ");          
                          String msg = in.nextLine();
                          byte[] wordInBytes = msg.getBytes();
                          fos.write(wordInBytes);
                          fos.flush();
                          fos.close();
                          
                     }
                     catch(Exception e)
                     {
                          System.out.println(e);
                     }
      Thank you for any help,