aspose file tools*
The moose likes Beginning Java and the fly likes Weird bufferedWriter behavior. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Weird bufferedWriter behavior." Watch "Weird bufferedWriter behavior." New topic
Author

Weird bufferedWriter behavior.

Lee Ringham
Greenhorn

Joined: Nov 17, 2012
Posts: 3
Hello, I'm having weird behavior from the bufferedWriter class.
Basically, If I do a System.out.print(text) and a fileWriter.write(text) they produce different results.

The system.out will create something like this:

[0] table [999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999] via [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,]

and the fileWriter will do this:

せ⁝慴汢⁥㥛㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹崬瘠慩嬠ⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰ⁝਍せ⁝慴汢⁥㥛㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹㤬㤹崬瘠慩嬠ⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰ⁝਍せ⁝慴汢⁥せㄬ崬瘠慩嬠ⰰⰱⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰ⁝਍せ⁝慴汢⁥せㄬ崬瘠慩嬠ⰰⰱⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰⰰ਍

The really weird thing is that in notepad++ the output from fileWriter is fine but when I open in regular notepad I get these Korean symbols.. Anyone know what I can do to have consistent output?

Thanks for your feedback, I'm pretty new here so I hope I didn't break any forum rules :p.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

Welcome to the Ranch.

Can you show us the code that produces this difference? It's a bit hard to say what's wrong without seeing the code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Lee Ringham
Greenhorn

Joined: Nov 17, 2012
Posts: 3
Thanks for the welcome! It's cool to find a community like this.

So, I'm trying to update log files and for the most part what I am writing to to log files comes from
the Util.printdv(); method. This was provided by my instructor and I have no access to the source
code, only a jar file. I can only assume that is correct.

I have also tried by generating my own text for the log with for loops and such but I still get the same
results... Korean text, lol.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
Which encoding are you using? that might be a wrong encoding problem. Have a look at the amusing Joel Spolsky article about it.
Lee Ringham
Greenhorn

Joined: Nov 17, 2012
Posts: 3
I got it to work by realizing I was writing the wrong message and should have been using a toString method instead.
I still don't know what exactly caused the problem though :p.
Very interesting article. I learned quite a bit.

Thanks for the help!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40059
    
  28
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird bufferedWriter behavior.