Discuss / Java / 为什么最后输出的中文是乱码呢

为什么最后输出的中文是乱码呢

Topic source

static void copy(String source, String target) throws IOException {

try (InputStream input = new FileInputStream("D:\\Program Files\\eclipse\\io-copy\\src\\"+source);OutputStream output = new FileOutputStream("D:\\Program Files\\eclipse\\io-copy\\src\\"+target)){

int n;

StringBuilder sb = new StringBuilder(1024);

while ((n = input.read()) != -1) {

sb.append((char)n);

}

System.out.print(sb.toString());

output.write(sb.toString().getBytes("UTF-8"));

}

}

中文变成了类似这个东西 -> 为啥中文不行呢

因为这是字节流


  • 1

Reply