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.lnx.en.html). Following its advice, I simply change LANG from en_US.UTF8 to en_US. Problem solved!

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <h1><h2><h3><sub><sup><b><i><u><font><img>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
Nice place