写文件 import java.io.FileNotFoundException; import java.io.FileOutputStream;//写文件 public class WriteFile { } 读文件 import java.io.FileInputStream;//读文件 public class ReadFile { 回-1; } } } fis.close(); System.out.println(result); if(num==-1)break; result=result+new String(b,0,num); public static void main(String[] args) throws Exception { FileInputStream fis=new FileInputStream("D:\\GUI\\test.txt"); byte[] b=new byte[1024]; String result=""; while(true){ int num=fis.read(b);//num返回实际读到的字节数,如果文件读完了返public static void main(String[] args) throws Exception { } String temp="Hello world!\n"; FileOutputStream fos=new FileOutputStream("D:\\GUI\\write.txt",true);//两个参数,true表示在文件末尾追加 fos.write(temp.getBytes()); fos.close();//流要及时关闭 本文来源:https://www.wddqw.com/doc/f0ad757ef46527d3240ce048.html