The system cannot find the file specified in java

前端 未结 8 896
轮回少年
轮回少年 2020-11-28 08:52

I am making a program that opens and reads a file. This is my code:

import java.io.*;

public class FileRead{
    public static void main(String[] args){
           


        
8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 09:15

    How are you running the program?

    It's not the java file that is being ran but rather the .class file that is created by compiling the java code. You will either need to specify the absolute path like user1420750 says or a relative path to your System.getProperty("user.dir") directory. This should be the working directory or the directory you ran the java command from.

提交回复
热议问题