Java Unicode to Java

public static void unicode2Java(String fileName, String outputFilePath) throws IOException {
		File f = new File(fileName);
		if (!f.exists()) {
			XLog.log("文件:" + fileName + "不存在!");
			return;
		}
		Path outPath = Paths.get(outputFilePath);
		if (!Files.exists(outPath)) {
			Files.createDirectory(outPath);
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
		BufferedWriter bw = new BufferedWriter(
				new OutputStreamWriter(new FileOutputStream(outputFilePath + File.separator + fileName)));
		int ch = -1;
		while ((ch = br.read()) != -1) {
			if (ch == '\\') {
				ch = br.read();
				if (ch == 'u') {
					String s = "";
					for (int i = 0; i < 4; i++) {
						ch = br.read();
						s += (char) ch;
					}
					bw.write(Integer.parseInt(s, 16));
					XLog.print(s);
				} else {
					bw.write(ch);
					XLog.print(ch);
				}
			} else {
				bw.write(ch);
				XLog.print(ch);
			}
		}
		XLog.println();
		br.close();
		bw.close();

	}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章