免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4312 | 回复: 2
打印 上一主题 下一主题

FileReader的read(byte[])方法疑问 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-03-18 23:51 |只看该作者 |倒序浏览
/**
* @(#)FileStream.java
*
*
* @author
* @version 1.00 2008/3/18
*/


import java.io.*;
public class FileStream {

    public static void main(String [] args) {
        File f = new File("hello.txt");
        try{
            //FileOutputStream out = new FileOutputStream(f);

            FileWriter out =new FileWriter(f);
            //byte buf[]="www.it315.org".getBytes();

            //out.write(buf);

            out.write("www.it315.org");
            out.close();
        }
        catch(Exception e) {
            System.out.println(e.getMessage());
        }
        
        try{
            //FileInputStream in = new FileInputStream(f);

            FileReader in = new FileReader(f);
            byte [] buf =new byte[1024];
            int len = in.read(buf);
            System.out.println(new String(buf,0,len));
        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
    }
}


这是一段学习例子,但是,我却如何都无法标以通过.
错误一直如下,实在不知道原因在何处,望大伙指教一二.谢谢.

标以错误如下:
--------------------Configuration: <Default>--------------------
E:\JavaPro\FileStream.java:30: 找不到符号
符号: 方法 read(byte[])
位置: 类 java.io.FileReader
            int len = in.read(buf);
                            ^
1 错误

Process completed.

论坛徽章:
0
2 [报告]
发表于 2008-03-19 10:41 |只看该作者
学习编程必须要先学会看文档,如果你看过文档,就应该知道只有read(char[])而没有read(byte[])

论坛徽章:
0
3 [报告]
发表于 2008-03-19 21:08 |只看该作者

回复 #2 perryhg 的帖子

您好,谢谢你的提示,
昨晚我是看过文档的,也看到过,结果还是忽略掉了这个。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP