Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Thai Language Encoding with TIS-620

807589Jul 10 2008 — edited Jul 14 2008
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              &#3612;&#3641;&#3657;&#3592;&#3633;&#3604;&#3585;&#3634;&#3619;&#3650;&#3619;&#3591;&#3648;&#3619;&#3637;&#3618;&#3609;&#3617;&#3633;&#3608;&#3618;&#3617;&#3623;&#3636;&#3592;&#3633;&#3618;&#3619;&#3632;&#3648;&#3610;&#3637;&#3618;&#3610;&#3648;&#3585;&#3603;&#3601;&#3660;&#3604;&#3657;&#3634;&#3609;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3593;                             
000002 7441 7454797 1681016631 000000057153890 080429 0190014757              &#3624;&#3638;&#3585;&#3625;&#3634;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3657;&#3629;&#3594;&#3656;&#3629;&#3591;&#3623;&#3636;&#3607;&#3618;&#3634;&#3594;&#3609;&#3593;&#3633;                                 
000003 7441 7454797 4162503389 000000090107942 080429 0190014762              &#3612;&#3641;&#3657;&#3592;&#3633;&#3604;&#3585;&#3634;&#3619;&#3650;&#3619;&#3591;&#3648;&#3619;&#3637;&#3618;&#3609;&#3617;&#3633;&#3608;&#3618;&#3617;&#3623;&#3636;&#3592;&#3633;&#3618;&#3619;&#3632;&#3648;&#3610;&#3637;&#3618;&#3610;&#3648;&#3585;&#3603;&#3601;&#3660;&#3604;&#3657;&#3634;&#3609;&#3604;&#3639;&#3657;&#3629;&#3604;&#3639;&#3593;                            
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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2008
Added on Jul 10 2008
10 comments
3,448 views