Passing file path as an argument in Java

前端 未结 4 1944
無奈伤痛
無奈伤痛 2020-12-19 06:01

I have been working with buffering a file on my local drive to parse and obtain certain data. For test purposes I was easily able to do it this way:

public s         


        
4条回答
  •  鱼传尺愫
    2020-12-19 06:35

    If you want to replace the hard coded path with one that you are passing via the command line, you should just be able to pass it in as a String. Your code will not read:

    ...
    File CP_file = new File(arg[0]);   //Assuming that the path is the first argument
    ...
    

    Be sure to quote the path on the CLI, especially if it contains white space or other special characters.

提交回复
热议问题