小编use*_*205的帖子

如何检查文件是否被打开

我需要帮助的只是测试文件是否已打开。

这是我所拥有的:

public static void main(String[] args) {

    //Prompt user to input file name
    SimpleIO.prompt("Enter File name: ");
    String fileName = SimpleIO.readLine();

    //Create file object 
    File file = new File (fileName);

    //Check to see if file is opened 

    if (!file.exists()){
        System.out.println("The file you entered either do not exist or the name is spelled wrong.\nProgram is now being terminated.\nGoodbye!");}
}
Run Code Online (Sandbox Code Playgroud)

java

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

标签 统计

java ×1