Java读取文件内容并转换为字符串

Java字符串与文件相互转换工具(一个非常实用的工具类)

转载自:http://lavasoft.blog.51cto.com/62575/d-7

Java读取文件内容并转换为字符串

转载自:http://blog.csdn.net/longronglin/article/details/1402267

        String FileName="d:/2.txt";
        File myFile=new File(FileName);
        if(!myFile.exists())
        
            System.err.println("Can't Find " + FileName);
        }


        try 
        {
            BufferedReader in = new BufferedReader(new FileReader(myFile));
            String str;
            while ((str = in.readLine()) != null
            {
                  System.out.println(str);
            }

            in.close();
        }
 
        catch (IOException e) 
        {
            e.getStackTrace();
        }

 

测试通过 


posted on 2012-03-21 12:22  yang3wei  阅读(2176)  评论(0编辑  收藏  举报