First, read the Unicode file
/**
* Read Unicode encoded text file
* @param resource String-filename
* @return String-unicode text
*/
public static string Read_uni (string resource) {
byte word_uni[] = new byte[1024];
String strreturn = null;
InputStream is;
try {
is = Instance.getclass (). getResourceAsStream (Resource);
Is.skip (2); Skip two-byte file headers
Is.read (Word_uni);
Is.close ();
StringBuffer StringBuffer = new StringBuffer ("");
for (int j = 0; J < Word_uni.length;) {
int l = word_uni[j++];
int h = word_uni[j++];
char C = (char) ((L & 0xff) | ((H << 8) & 0xff00));
Stringbuffer.append (c);
}
Strreturn = Stringbuffer.tostring ();
catch (IOException ex) {
System.out.println (ex);
finally {
is = null;
}
return strreturn;
}
Second, read UTF-8 files
/**
* Read UTF-8 encoded text file
* @param resource String-filename
* @return String-utf-8 text
*/
public static string Read_utf (string resource) {
byte word_utf[] = new byte[1024];
String strreturn = null;
InputStream is;
try {
is = Instance.getclass (). getResourceAsStream (Resource);
Is.read (WORD_UTF);
Is.close ();
Strreturn = new String (Word_utf, "UTF-8");
catch (IOException ex) {
System.out.println (ex);
}
return strreturn;
}