Relative/Absolute Path in Java

前端 未结 2 1030
青春惊慌失措
青春惊慌失措 2021-01-29 14:41

I need to write a program that asks for the file name of a text document of number and then calculates average, median, etc., from this data set. I have written the program so

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-29 14:59

    Your program needs to know the full path in order to find the file. It isn't just searching your computer for the file "inputValues2.txt". It needs to know exactly how to get there. If you wanted to, you could move the file into your project folder, and then you would just be able to write "inputValues2.txt" to access it. I normally create a folder called "res" in my project folder, and then let's say I am trying to create an image:

    Image i = new Image("res/img.png");
    

提交回复
热议问题