转文件编码格式

@Test
	public void testConvert() throws Exception {
		convertEncode(new File("F:\\Workspaces1\\ediorDWEditor"), "GB2312", "utf-8");

	}

	private static void convertEncode(File file, String inputEncode, String outputEncode) throws IOException {
		if (file.isFile() && (file.getName().endsWith(".mxi") || file.getName().endsWith(".html") || file.getName().endsWith(".js")||file.getName().endsWith(".xml"))) {
			System.out.println("转化"+file.getName());
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), inputEncode));
			ArrayList<String> lines = new ArrayList<String>();
			String line;
			while ((line = br.readLine()) != null)
				lines.add(line);
			br.close();
			PrintStream out = new PrintStream(file, outputEncode);
			for (String s : lines)
				out.println(s);
			out.flush();
			out.close();
		} else if (file.isDirectory()) {
			File[] files = file.listFiles();
			if (files != null) {
				for (File f : files)
					convertEncode(f, inputEncode, outputEncode);
			}
		}
	}

你可能感兴趣的:(编码格式)