RandomAccessFile用法

*、RandomAccessFile之读取文件且同时修改编码

StringBuffer localStringBuffer = new StringBuffer();
RandomAccessFile localRandomAccessFile = new RandomAccessFile(
		sNewFileName, "r");
long l1 = localRandomAccessFile.length();
for (long l2 = 0L; l2 < l1; l2 = localRandomAccessFile.getFilePointer()) {
	String str2 = localRandomAccessFile.readLine();
	str2 = new String((str2.getBytes("iso8859-1")), "UTF-8");
	localStringBuffer.append(str2);
	localStringBuffer.append("\r\n");
}
localRandomAccessFile.close();
其中:"r"表示仅可读
    sNewFileName表示全路径的文件
    localStringBuffer最终编码后的字符变量对象

猜你喜欢

转载自lbovinl.iteye.com/blog/2345019