当前位置: 代码迷 >> Java相关 >> Filewriter 求解!!!!
  详细解决方案

Filewriter 求解!!!!

热度:408   发布时间:2011-10-15 13:34:04.0
Filewriter 求解!!!!
请高手 指导一下,为何 FileWriter 中 要在 pubilc 类的 main 方法后面加 throws IOException?
还有 就是,为何 不能用 Filewriter 对象 往文件中写 long 类型的数据?
谢谢!!!
搜索更多相关的解决方案: long  

----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽
2011-10-15 06:00:16
xianglgd

等 级:新手上路
帖 子:15
专家分:5
注 册:2011-10-15
  得分:0 
回复 2楼 付政委
import java.util.Scanner;
import java.io.*;

public class basicType {

    public static void main(String[] args) throws IOException {
        String s1,s2;
        s1="Hellow,how are you?";
        s2="Hellow,how are you?";
        if(s1.equals(s2))
            System.out.println(s1);
        long Long=99999;
        int sum=0,i;
        String s3=" ";
        Scanner input=new Scanner(System.in);
        System.out.println("输入一些整数 以0结束。");
        do
        {
            try{
            i=input.nextInt();
            }
        catch(Exception e)
        {
            s3=input.next();
            i=1;
            continue;
        }
            sum+=i;
        }while(i!=0);
        System.out.println(sum);
        
        File f1=new File("E:\\2010javazhw\\java编程文件目录\\test.txt");
        FileWriter fw=new FileWriter(f1,true);
        fw.write(sum);
        fw.write('f');
        fw.write(s1);
        fw.write(Long);
        fw.close();
        int k;
        long l_1;
        String st;
        char ch;
        FileReader fr=new FileReader(f1);
        k=fr.read();
        System.out.println(k);
        ch=(char)fr.read();
        System.out.print(ch);
        //st=fr.read();
        
        
        
    }

}

顺便问一下,为何 一定要抛出异常?详细点,谢谢,还有就是 Filereader 如何才能 读 一长串字符?


----------------解决方案--------------------------------------------------------