流的读写 File file = new File("C:\\Users\\dell\\Desktop\\HW\\t.txt"); System.out.println(file.toString()); File file1= new File("C:\\Users\\dell\\Desktop\\HW\\hello.txt"); InputStream is=new FileInputStream(file); OutputStream out=new FileOutputStream(file1); //定义byte数组用来暂存数据 byte[] buf = new byte[1024]; //读取Is中的内容存到buf is.read(buf); //将buf中的内容写入out out.write(buf); is.close(); out.close();
通过流向文件中写入内容
FileWriter fileWriter = new FileWriter("text.txt"); fileWriter.write("终归你好·1"); fileWriter.write("终归你好·2"); fileWriter.write("终归你好·3"); fileWriter.write("终归你好·4"); fileWriter.close();