1 Reply Latest reply: Nov 11, 2009 11:04 AM by 807580 RSS

    Writing to file(using PrintWrier)

    807580
      Im trying to do a simple program that will write system information into a file for data basing.
      But the problem is it creates the file but does not write anything ive used other methods. But they would
      not let me write to a new line in the .dat file. Im looking for a quick and easy solution. Help is appreciated


      import java.io.*;
      import java.util.*;
      
      
      public class MLS_writer {
           public static void main(String args [] ) {
           
           try{
                
                PrintWriter out = new PrintWriter(new FileWriter("C:\\bank.dat"));
                // make file writer
                     out.println("USER DATA");
                     out.println("User name=");
                     String getinput;
                     System.out.println("Enter the account your currently logged in on");
                     Scanner getin = new Scanner(System.in);
                     getinput =     getin.next();
                     
                     out.println(getinput);
                     //out.println ("\n");
                     //out.println("Computer operationg sysetm=");
                     System.out.println("Enter computer operating system.");
                     String osinput;
                          
                     osinput = getin.next();
                     out.println("operationg system=" + osinput);
                     //out.write("\n");
                     out.println("Command line/shell=default");
                     //out.write("\n");
                     }catch (Exception e) {
                     
                          System.out.println("Error: " + e.getMessage());
                          System.out.println("Unable to write file Mbank.dat");
                     
                     
                     }
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
           }
      
      }