小编use*_*420的帖子

在Java中将文件路径作为参数传递

我一直在缓冲本地驱动器上的文件来解析并获取某些数据.出于测试目的,我很容易就能这样做:

public static void main(String[] args) {

    fileReader fr = new fileReader();
    getList lists = new getList();


    File CP_file = new File("C:/Users/XYZ/workspace/Customer_Product_info.txt");
    int count = fr.fileSizeInLines(CP_file);
    System.out.println("Total number of lines in the file are: "+count);

    List<String> lines = fr.strReader(CP_file);

    ....

}

}
Run Code Online (Sandbox Code Playgroud)

fileReader.java文件具有以下功能:

public List<String> strReader (File in)
{
    List<String> totLines = new ArrayList<String>();

    try
    {
        BufferedReader br = new BufferedReader(new FileReader(in));
        String line;
        while ((line = br.readLine()) != null)
        {
            totLines.add(line);
        }
        br.close();
    }
    catch (FileNotFoundException e) {
        e.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud)

java command-line-arguments

6
推荐指数
2
解决办法
7万
查看次数

标签 统计

command-line-arguments ×1

java ×1