开发者

file not found while executing

import java.io.*;

public class NumberOfLine{
    public static void main(String[] args) {
        try{
            System.out.println();
            System.out.println("Getting line number of a paritcular file example!");
                System.out.println("***************************************************************");
                System.out.println();


        //  FileInputStream fstream = new FileInputStream("F://Inputfile.txt");
        //  DataInputStream in = new DataInputStream(fstream);
        //  System.out.println();
        //  BufferedReader bf = new BufferedReader(new InputStreamReader(in));
        //  String strLine;

            FileInputStream fstream = new FileInputStream("F://Inputfile.txt");
            BufferedReader bf = new BufferedReader(new InputStreamReader(fstream));
            DataInputStream in = new DataInputStream(fstream);


//      System.out.println("Please enter file name (location) with extension:");


            String str = bf.readLine();
            File file = new File(str);
            i开发者_运维问答f (file.exists()){
                FileReader fr = new FileReader(file);
                LineNumberReader ln = new LineNumberReader(fr);
                int count = 0;
                while (ln.readLine() != null){
                    count++;
                }
                System.out.println("Total line no: " + count);
                ln.close();
            }
            else{
                System.out.println("File does not exists!");
            }
        }
        catch(IOException e){
            e.printStackTrace();
        }
    }
}


Your code says to read the file whose path is given as the first line of the InputFile.txt. Is that what you intended? If so, try changing the first line of InputFile.txt to have the absolute path. If that works, try reworking your original path.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜