您的位置:首页 > 其它

How to read file line by line?

2008-07-16 16:58 302 查看
since readLine() of DataInputStream is depreacted, now we can use BufferReader to do this job.

public static void main(String args[]){
        try {
            File file = new File("d://myfile.txt");
            FileInputStream fis = new FileInputStream(file );
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
             
            String line = null;
             while (( line = br.readLine()) != null){
                System.out.println(line);
             }
              fis.close();
              br.close();

            } catch (FileNotFoundException e) {
              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  file string null