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 );                    


Recommended Answers

All 3 Replies

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.

you maybe need to close the file after editing..

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.