This kind of output is caused by a mismatch somewhere - your file is encoded in UTF-8 but the console where you print the data expects a single-byte encoding such as Windows-1252.
You need to (a) ensure you read the file as UTF-8 and (b) ensure you write to the console using the encoding it expects.
FileReader
always uses the platform default encoding when reading files. If this is UTF-8 then
- your Java code reads the file as UTF-8 and sees
Céleste
- you then print out that data as UTF-8
- in NetBeans the console clearly expects UTF-8 and displays the data correctly
- outside NetBeans the console expects a single-byte encoding and displays the incorrect rendering.
Or if your default encoding is a single byte one then
- your Java code reads the file as a single byte encoding and sees
Céleste
- you then print out that data as the same encoding
- NetBeans treats the bytes you wrote as UTF-8 and displays
Céleste
- outside NetBeans you see the wrong data you originally read.
Use an InputStreamReader
with a FileInputStream
to ensure you read the data in the correct encoding, and make sure that when you print data to the console you do so using the encoding that the console expects.