ITeye博客

去除bom方法

mapengfei00099 · 2013-07-08 09:24 · 编程语言 · Markdown

	public static void trimBom(String fileName) throws IOException {

		FileInputStream fin = new FileInputStream(fileName);
		// 开始写临时文件
		InputStream in = fin;
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		byte b[] = new byte[4096];

		int len = 0;
		while (in.available() > 0) {
			len = in.read(b, 0, 4096);
			// out.write(b, 0, len);
			bos.write(b, 0, len);
		}

		in.close();
		fin.close();
		bos.close();
		// 临时文件写完,开始将临时文件写回本文件。
		FileOutputStream out = new FileOutputStream(fileName);
		out.write(bos.toByteArray());
		out.close();

	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。