利用StringBuffer读写文件实例

public class stringBuffertest {
	public static void main(String[] args) {
		try {
			FileInputStream fis = new FileInputStream("C:/test.txt");
			FileOutputStream fos = new FileOutputStream("E:/test.txt");
			
			StringBuffer sb = new StringBuffer();
			byte[] bytes = new byte[1024];//建立缓冲区
			int a = 0;//确定读取位置
			while((a = fis.read(bytes)) != -1){
				sb.append(bytes);
			}
			fos.write(Integer.parseInt(sb.toString()));//将StringBuffer中的数据写入E盘中

		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}	
}

你可能感兴趣的:(利用StringBuffer读写文件实例)