| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:Filewriter 求解!!!!
只看楼主 加入收藏
xianglgd
Rank: 1
等 级:新手上路
帖 子:15
专家分:5
注 册:2011-10-15
结帖率:66.67%
收藏
已结贴  问题点数:0 回复次数:2 
Filewriter 求解!!!!
请高手 指导一下,为何 FileWriter 中 要在 pubilc 类的 main 方法后面加 throws IOException?
还有 就是,为何 不能用 Filewriter 对象 往文件中写 long 类型的数据?
谢谢!!!
搜索更多相关主题的帖子: long 
2011-10-15 13:34
付政委
该用户已被删除
收藏
得分:20 
提示: 作者被禁止或删除 内容自动屏蔽
2011-10-15 14:00
xianglgd
Rank: 1
等 级:新手上路
帖 子:15
专家分:5
注 册:2011-10-15
收藏
得分:0 
回复 2楼 付政委
import java.util.Scanner;
import *;

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 如何才能 读 一长串字符?

2011-10-15 14:05
快速回复:Filewriter 求解!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011480 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved