-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDecodeUtf8.java
executable file
·34 lines (28 loc) · 1.02 KB
/
DecodeUtf8.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.*;
public class DecodeUtf8 {
public static void main(String[] args){
System.out.println("BEGIN");
String value="\\192.168.15.21\\scan\\EXP_DATA\\BonCard1 ARMA_ÐакеÑ2_4.tif";
//String value="ÐакеÑ.tif";
System.out.println("Decode: "+decodeUtf(value));
System.out.println("Decode: "+decodeUtf("вввааа"));
}
private static String decodeUtf(String value){
String returnValue="";
byte[] array=new byte[value.length()];
for(int counter=0;counter<value.length();counter++){
array[counter]=(byte)value.charAt(counter);
}
try {
ByteArrayInputStream bais=new ByteArrayInputStream(array);
InputStreamReader isr=new InputStreamReader(bais,"UTF-8");
BufferedReader reader=new BufferedReader(isr);
returnValue=reader.readLine();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}catch(Exception ex){
System.out.println("Exception: "+ex.getMessage());
}
return returnValue;
}
}