码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-10-17 11:57:41      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   java   文件   div   2014   on   问题   

我的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();
			}
		}
	}
}

在编译时出现错误:

bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣

这是因为代码中出现了utf-8字符,解决方案如下:

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

bubuko.com,布布扣

在此编译,没有问题:

bubuko.com,布布扣

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

标签:http   io   ar   java   文件   div   2014   on   问题   

原文地址:http://blog.csdn.net/lasolmi/article/details/40183215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!