Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“线程中的异常”;“主要”;java.io.FileNotFoundException:(句柄无效)_Java_File_Netbeans - Fatal编程技术网

“线程中的异常”;“主要”;java.io.FileNotFoundException:(句柄无效)

“线程中的异常”;“主要”;java.io.FileNotFoundException:(句柄无效),java,file,netbeans,Java,File,Netbeans,我正在尝试循环浏览一个包含各种选项的菜单。选项1涉及从.json文件读取 但我一直在犯这样的错误: Exception in thread "main" java.io.FileNotFoundException: (The handle is invalid) at java.base/java.io.FileInputStream.open0(Native Method) at java.base/java.io.FileInputStream.open

我正在尝试循环浏览一个包含各种选项的菜单。选项1涉及从.json文件读取

但我一直在犯这样的错误:

Exception in thread "main" java.io.FileNotFoundException:  (The handle is invalid)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
    at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
    at java.base/java.io.FileReader.<init>(FileReader.java:60)
    at com.malikrobinson.presentation.Main.main(Main.java:43)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:764)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine (ExecMojo.java:711)
    at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:289)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time:  5.264 s
Finished at: 2020-10-05T16:17:35-04:00
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project YouDontNeedToKnow: Command execution failed.: Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
我就是不明白为什么会出现这个错误。我有一个“抛出FileNotFoundException”。
我对Java和Netbeans的所有了解都告诉我,只要输入循环选项,我就不会有问题。

我最终发现while循环的这种配置使程序工作正常:

Scanner keyboard = new Scanner(System.in);
    
    while (choice != 4) {
        //First prompting of the menu
        System.out.println(menu);
        choice = keyboard.nextInt();
        
        //Program does no work unless this is here.
        ofileName = keyboard.nextLine();

我不知道确切的原因,但确实如此。

你输入了什么?@Spectric我输入了“1”,然后按回车键。哪个应该执行switch语句案例1中的命令。您确定吗?如果键入1,则应键入另一个字符串,该字符串应为文件名。一旦显示“Enter Shift JSON Input Filename\n”,它将立即出错。没有机会输入文件名.Hmm,即使我注释掉了所有内容,除了,`System.out.println(“Enter Shift JSON Input Filename\n”);ifileName=keyboard.nextLine();`它只是跳过让我输入任何内容,然后再次显示菜单。
Scanner keyboard = new Scanner(System.in);
    
    while (choice != 4) {
        //First prompting of the menu
        System.out.println(menu);
        choice = keyboard.nextInt();
        
        //Program does no work unless this is here.
        ofileName = keyboard.nextLine();