php网站容量/如何创建一个网页
读取文件内容:FileInputStream、FileReader
写入内容到文件:FileOutputStream、FileWriter
ex:
/*** 使用文件流来读取文件内容和写入内容到一个文件中* 读取文件内容:FileInputStream、FileReader* 写入内容到文件:FileOutputStream、FileWriter* @author 郑清*/
public class Demo {public static void main(String[] args) throws IOException {// TODO Auto-generated method stub//1.创建字节输入流对象FileInputStream fis = new FileInputStream("D:1/1.txt"); //2.读取内容int read;while((read = fis.read()) != -1) {System.out.print((char)read);} //3.关闭流fis.close();//1.创建字节输出流对象FileOutputStream fos = new FileOutputStream("D:1/1.txt");//2.写fos.write("这是要写入的内容!".getBytes());//3.关闭流fos.close();//1.创建字符输入流对象FileReader fr = new FileReader("D:1/1.txt");//2.读int read2;while((read2 = fr.read()) != -1) {System.out.print((char)read2);}//3.关闭流fr.close();//1.创建字符输出流对象FileWriter fw = new FileWriter("D:1/1.txt");//2.写fw.write("我要用字符输出流写东西了!!");//3.关闭流fw.close();}}