Вопрос

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?

Это было полезно?

Решение

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

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

Другие советы

You are writting a number. It means that you write the bytes of the number (0x0000000A), not its character representation 10. When you open it with notepad or the like, it just finds that it does not contain printable ASCII values and you only see it blank.

Use write.write(Integer.toString(upto)) to see the difference.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top