read:
import java.io.FileReader; //导入包
import java.io.IOException; //导入包
public class read {
package com.chinasoft.java.wangluobiancheng; import java.io.FileReader; import java.io.IOException; public class read { public static void main(String []args)throws IOException{ FileReader f2=new FileReader("haha1.txt"); int i= f2.read(); while(i!=-1){ System.out.print((char)i); i=f2.read(); } //while((f2.read())!=-1){ // System.out.print((char)f2.read()); //} f2.close(); } }
write:
import java.io.File; import java.io.FileWriter; import java.io.IOException; public class write { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub FileWriter f1=new FileWriter("haha1.txt"); String str="hahahha"; f1.write("hahahha"); f1.flush(); f1.close(); } }
时间: 2024-11-29 05:21:07