Mohamed Sanaulla | My Blog | Author of Java 9 Cookbook | Java 11 Cookbook
abalfazl hossein wrote:Is there any special reason that the count of member in byte array is 1024?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
FileReader always uses the platform default encoding which is generally a bad idea.
or example you could not read a chinese file with filereader. (you'd read it but not correctly)
Êæ
abalfazl hossein wrote:definitely I can save a file so I choose the encoding
and When I check the encoding of files, I see that encoding came back to default: ANSI
Another way, It is said that when you choose FileWriter, It chooses deault encoding that is used by Operation System.The default encoding that is used for txt files in windows is ANSI.I think that that is why the encoding of file return back to ANSI, After the running of the program.
Is my guess correct?
abalfazl hossein wrote:When I check the encoding of files, I see that encoding came back to default: ANSI
The default encoding that is used for txt files in windows is ANSI.
Where do you see that? What piece of software tries to determine the encoding?
FileReader always uses the platform default encoding which is generally a bad idea.
abalfazl hossein wrote:Please look at the image again Sir, In the bottom of image, I can choose Unicode, UTF8, ANSI...
The default for txt file is ANSI in windows
While using FileReader, JAVA uses default encoding of operation system. That is here ANSI.
Check the "file.encoding" system property of your JVM if you want to know for sure.
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in=null;
BufferedWriter out=null;
// Open file to be copied
in=new BufferedReader(new InputStreamReader(new FileInputStream("mytext.txt"),"UTF8"));
// And where to copy it to
out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("mytextcopy.txt",true),"UTF8"));
String line = null;
while ((line=in.readLine()) != null) {
out.write(line);
out.newLine(); // Write system dependent end of line.
}
// close both streams
in.close();
out.close();
}
}
I promise I will be the best, most loyal friend ever! All for this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|