我的java文件里出现中文,是这样一个文件:

import java.io.*;
public class Test {
	public static void main(String[] args) {
		String separator = File.separator;
		String filename = "myfile.txt";
		String directory = "mydir1" + separator + "mydir2";
		File f = new File(directory , filename);
		if(f.exists()) {
			System.out.println("文件名称:" + f.getAbsolutePath());
			System.out.println("文件大小:" + f.length());
		} else {
			f.getParentFile().mkdirs();
			try {
				f.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

在编译时出现错误:

Java中出现“错误: 编码GBK的不可映射字符”的解决方法
Java中出现“错误: 编码GBK的不可映射字符”的解决方法
Java中出现“错误: 编码GBK的不可映射字符”的解决方法

这是由于代码中出现了utf-8字符。解决方式例如以下:

用notepad打开该java文件,另存为,编码为ANSI

Java中出现“错误: 编码GBK的不可映射字符”的解决方法

在此编译。没有问题:

Java中出现“错误: 编码GBK的不可映射字符”的解决方法

相关文章:

  • 2021-10-14
  • 2021-12-03
  • 2021-06-02
  • 2021-12-04
  • 2021-09-23
  • 2022-12-23
  • 2021-06-15
猜你喜欢
  • 2021-11-13
  • 2021-12-22
  • 2022-12-23
  • 2021-04-24
相关资源
相似解决方案