Reputation: 735
If Two different machines have different character encodings.How to take from a java program that same file on both machines should be read in similar manner.Is it possible using java or we have to manually set the encodings of both machines?
Upvotes: 0
Views: 694
Reputation: 80186
You are in control of reading/writing the files on both environment.
Working with text files in Java
You have control control on only read side.
UPDATE
If your issues is that you are not seeing the output properly in eclipse console then the issue might be with the encoding setting of the eclipse itself. Read this article on how to fix eclipse.
Upvotes: 0
Reputation: 1454
You don't need to change the machine's settings.
You can use any java.io.Reader subclass that allows you to set the character encoding. For instance InputStreamReader, like so:
new InputStreamReader(new FileInputStream("file.txt"), "UTF8");
Upvotes: 0
Reputation: 1500785
It sounds like you just want to use something like:
InputStream inputStream = new FileInputStream(...);
Reader reader = new InputStreamReader(reader, "UTF-8"); // Or whatever encoding
Basically you don't have to use the platform default encoding, and you should almost never do so. It's a pain that FileReader
always uses the platform default encoding :( I prefer to explicitly specify the encoding, even if I'm explicitly specifying that I want to use the platform default :)
Upvotes: 2