A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 王璐 中级黑马   /  2012-7-20 21:41  /  1821 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 王璐 于 2012-7-21 08:21 编辑

package shiyan;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
class Demo
{
        public static void main(String[] args) throws IOException
        {
        BufferedReader bufr = new BufferedReader(new FileReader("info.txt"));
        String line = null;
        Properties prop = new Properties();
        while((line=bufr.readLine())!=null)
        {
                String[] arr = line.split("=");
                ///System.out.println(arr[0]+"...."+arr[1]);
                prop.setProperty(arr[0],arr[1]);
        }
        bufr.close();
                System.out.println(prop);
        }
}

info.txt的位置和内容。



程序运行始终报错:
Exception in thread "main" java.io.FileNotFoundException: info.txt (系统找不到指定的文件。)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileInputStream.<init>(FileInputStream.java:66)
        at java.io.FileReader.<init>(FileReader.java:41)
        at shiyan.Demo.main(Demo.java:12)
这是为什么啊?

3 个回复

倒序浏览
路径问题
回复 使用道具 举报
BufferedReader bufr = new BufferedReader(new FileReader("src\\shiyan\\info.txt"));你要写成这样才行滴
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马