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

来源:互联网 发布:伊娃格林 知乎 编辑:程序博客网 时间:2024/06/06 14:15
        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();
        }

 

测试通过 

原创粉丝点击