Annoying sun.io.MalformedInputException when moving Java program from Windows to Linux

These day I write Java programs on my local machine and then move them to a Linux server to run experiments. This routine works fine so far. However, when I ran one of the progams, which involves coping one file from one directory to another, I kept on the following error message:

sun.io.MalformedInputException
at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java)
at java.io.InputStreamReader.convertInto(InputStreamReader.java:127)
at java.io.InputStreamReader.fill(InputStreamReader.java:176)
at java.io.InputStreamReader.read(InputStreamReader.java:256)
at java.io.BufferedReader.fill(BufferedReader.java:158)
at java.io.BufferedReader.read1(BufferedReader.java:206)
at java.io.BufferedReader.read(BufferedReader.java:280) 

First, I though it was because of the file format problem, since all the files to be moved were created on my local Windows machine. So I manually ran dos2unix command to all the files, but it didn't work. Then I tried to change my code so that it reads and write the files in UTF8 encoding. It still did not help. Finally, I found this post online (http://www-128.ibm.com/developerworks/java/jdk/linux/142/runtimeguide.ln...). Following its advice, I simply change LANG from en_US.UTF8 to en_US. Problem solved!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <img> <h1><h2><h3><sub><sup><b><i><u><font>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
12 + 7 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.