1. 程式人生 > >read 和write

read 和write

exceptio ner row obia code stat java lose ted

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(); } }



read 和write