码迷,mamicode.com
首页 > 其他好文 > 详细

read 和write

时间:2017-06-28 11:51:05      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:eth   main   china   log   com   package   exce   todo   throws   

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

标签:eth   main   china   log   com   package   exce   todo   throws   

原文地址:http://www.cnblogs.com/-strong/p/7084711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!