Wednesday, June 16, 2010

READING UNICODE TEXT FROM A FILE IN JAVA

The Unicode will be in either in UTF-8 or UTF-16 format.

Code for reading UTF-16 file:

import java.io.*;

public class Unicode_read
{
public static void main(String args[])
{
FileInputStream fis=null;
BufferedReader br=null;
try
{
fis=new FileInputStream("unicodefile.txt");
br=new BufferedReader(new InputStreamReader(fis,"UTF-16"));
String h;
while((h=br.readLine())!=null)
{
//perform your task with the read string.
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

No comments:

Post a Comment