在Java中處理亂碼問題可以通過以下方式轉(zhuǎn)換亂碼為中文:
String str = "亂碼字符串";
byte[] bytes = str.getBytes("ISO-8859-1");
String chineseStr = new String(bytes, "UTF-8");
System.out.println(chineseStr);
InputStream inputStream = new FileInputStream("亂碼文件.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
以上是兩種常見的處理亂碼問題的方法,根據(jù)具體情況選擇適合的方法進(jìn)行轉(zhuǎn)換。