Hi All,
I have a file which has few Thai language words.I need to decode with TIS-620 charset.
I have tried with a standalone program.When I run the program and try to print the local lang program..it simply prints ??? in Eclipse console......When I try to print the Byte Array with the charset Name=TIS-620, it gives me..[B@7d772e and when I try to print it after decode the array of bytes with given char set as ISO8859_1..it prints some garbage characters....��������
I am attaching the java code I have been trying and also the file which I am trying to read.
{code}import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class te {
private static final String ISO = "ISO8859_1";
private static String charsetTobeChanged="TIS-620";
public static void main(String args[]) throws Exception{
BufferedReader brFile;
String inFileName=null ;
String inLine,inLine_BENE_NAME,decode_LL_BENE_NAME ;
inLine_BENE_NAME="test";
FileOutputStream fos2=new FileOutputStream("C:\\Documents and Settings\\Desktop\\asPerBaseFile.dat");
DataOutputStream output = new DataOutputStream (fos2);
final String NEXT_LINE = "\n";
inFileName= "C:\\Documents and Settings\\D150911\\Desktop\\latestBaseFile.dat" ;
String newStrLine,newDecodedBeneName;
try{
brFile = new BufferedReader(new InputStreamReader(new FileInputStream(inFileName), "UTF-8"));
while ((inLine = brFile.readLine()) != null) {
try{
inLine_BENE_NAME = getField(inLine, inLine.length(), 78, 128).trim();
if (inLine_BENE_NAME!=null && inLine_BENE_NAME.length()>0)
{
decode_LL_BENE_NAME = decode(inLine_BENE_NAME.getBytes(charsetTobeChanged),ISO);
newDecodedBeneName= fillSpace(decode_LL_BENE_NAME,50);
newStrLine=inLine.substring(0, 78).concat(newDecodedBeneName).concat(inLine.substring(128));
output.writeBytes(newStrLine);
output.writeBytes(NEXT_LINE);
}
else
{
output.writeBytes(inLine);
}
}//end try
catch (Exception encodeE)
{
System.out.println(" exception in Encoding=="+encodeE);
}
}//end while
}//end of try
catch(Exception e)
{
System.out.println("File not found= or any other exception ==="+e);
}
}
//getField
public static String getField(String lineString, int lineLength, int startPos, int endPos) throws Exception {
String outString;
try {
if (lineLength >= endPos) {
outString = lineString.substring(startPos, endPos);
} else
if (lineLength >= startPos) {
outString = lineString.substring(startPos, lineLength);
} else {
outString = "";
}
return(outString);
}
catch (Exception ex) {
throw ex;
}
}
public static String decode(byte[] pvBytes, String pvTargetCodePage) throws Exception
{
if(pvBytes == null)
return "";
return new String(pvBytes, pvTargetCodePage);
}
public static String fillSpace(String field_value, int number_of_digit)
{
String add_space = "";
if (field_value.length() < number_of_digit) {
for (int j=0; j<(number_of_digit - field_value.length()); j++) {
add_space = add_space + " ";
}
}
field_value = field_value + add_space;
return field_value;
} // fillSpace
}//end class
And the file which I am trying to read is following..please copy and paste as a file...
000001 7441 7454797 2721001477 000000050030932 080429 0190014754 ผู้จัดการโรงเรียนมัธยมวิจัยระเบียบเกณฑ์ด้านดื้อดืฉ
000002 7441 7454797 1681016631 000000057153890 080429 0190014757 ศึกษาดื้อดื้อดื้อดื้อดื้อดื้อดื้อดื้อช่องวิทยาชนฉั
000003 7441 7454797 4162503389 000000090107942 080429 0190014762 ผู้จัดการโรงเรียนมัธยมวิจัยระเบียบเกณฑ์ด้านดื้อดืฉ
000004 9100 7454797 0000000000 000000197292764 000000
==============================================
The above line is just a seperator...It can be noticed in the given file above the 3rd last line after LL has a Thai word which needs to be encoded....
I mean ,I want to decode it with Char set TIS-620 so that when I open it in IE..Thai language can be viewed by Thai encoding.
Please help.
Edited by: InfoRequired on Jul 11, 2008 1:11 AM