Search code examples
javabufferedwriterwriter

Weird FileWriter error


I have written to files before and never come across this problem, i am utterly confused.

EDIT: Sorry the error is that no lines are being written to the .txt file.

   System.out.println(upto); 
   FileWriter writer;
   BufferedWriter write;

   upto = 10;
    try{
    writer = new FileWriter(theFile);    
    write = new BufferedWriter(writer); 
    write.write(upto);
    write.flush();
    write.close();

    }catch(Exception e){
        System.err.println("cant print line");
    }

thats is the code that handels writing to the file, the only other code is declaring the file path. No exception error comes up either. I made sure that I was flushing/closing the writer too. Could someone help?


Solution

  • You are printing char 10, which is a line feed. If you want to print the number 10, try

    write.write(String.valueOf(upto));