利用StringBuffer读写文件实例

xiaoxiao2021-02-28  86

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(); } } }
转载请注明原文地址: https://www.6miu.com/read-78984.html

最新回复(0)