Can someone tell me why my data is not printing to my file. It will create the text file but it will not write to it.

Here is a snippett:

 out = new PrintWriter("completeAuto.txt");

            while ((car = br.readLine()) != null && (van = br1.readLine())!=null && (truck = br2.readLine()) != null) 
               out.print (car );                    


Re: Not Writing to Text File 80 80

The PrintWriter(String s) constructor does not contain automatic flushing to the writer. You need to use println statements to do this rather than print statements. Or immediately after your while loop call out.flush().
Also, I think maybe you need or statements in your while loop as opposed to and statements, but that may depend on what you are actually trying to achieve.

Re: Not Writing to Text File 80 80

you maybe need to close the file after editing..

Re: Not Writing to Text File 80 80

Small example how to write into file

class FileWrite 
   public static void main(String args[])
    // Create file 
    FileWriter fstream = new FileWriter("out.txt");
        BufferedWriter out = new BufferedWriter(fstream);
    out.write("Hello Java");
    //Close the output stream
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.