使用Intellij idea IDE读取文件 [英] Reading files with Intellij idea IDE

查看:1482
本文介绍了使用Intellij idea IDE读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个很长时间的eclipse用户,我已经开始使用IntelliJ Idea IDE。

I am a long time eclipse user and I have started to play around with IntelliJ Idea IDE.

所以从我的理解。 IntelliJ中的项目与Eclipse Workspace相同。同样,IntelliJ中的模块相当于eclipse中的项目。

So from my understanding. A project in IntelliJ is the same as the Eclipse Workspace. As well, a module in IntelliJ is the equivalent of a project in eclipse.

我在IntelliJ中创建了一个项目,但仍不确定为什么有一个src文件夹它应该是一个工作空间......

I created a project in IntelliJ, still not sure why there is a src folder in it if it is supposed to be a workspace...

之后,我在项目中创建了一个模块。我在模块的src中创建了一个类。我在类中创建的代码如下:

Afterwards, I create a Module in the project. I created a class inside the src of the module. The code I made inside the class is the following:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class MainClass {
    public static void main(String[] args) throws FileNotFoundException {
        System.out.println("Hello World!");
        Scanner input = new Scanner(new File ("test123.txt"));
        String answer = input.nextLine();
        System.out.println(answer);
    }
}

问题是我在尝试阅读时遇到错误文件。我尝试将.txt文件放在我的src文件中,该文件位于模块内部和src文件之外但在模块内部。但在这两种情况下都找不到该文件。是的,代码有效,我在Eclipse上尝试过,它运行正常。文件名也拼写正确。

The problem is that I get an error trying to read the file. I tried putting the .txt file inside my src file which is located inside the module and outside the src file but inside the module. But in both cases the file is not found. Yes the code works, I tried it on Eclipse and it works fine. The file name is spelled correctly as well.

这是我的项目/工作区的图片,如果有用的话:

Here is a picture of my project/workspace if it is helpful:

我为图片道歉太小了,你可以在这里找到一个更大的版本: http://oi60.tinypic.com/jg1g60.jpg

I apologize if the image is too small, you can find a larger version here: http://oi60.tinypic.com/jg1g60.jpg

推荐答案

只需将文件直接移动到调用Java的项目文件夹(因此主文件夹)(在您制作的蓝色模糊条带旁边:P)

Just move the file directly to the project folder which calls "Java" (so the main folder) (next to the blue-blurred strip you made :P)

或者如果没有帮助,则将test123.txt文件移动到FirstJavaProgram目录

or if it doesn't help, then move the test123.txt file to FirstJavaProgram directory

您还可以将文件名更改为以下其中一个:

you can also change filename to one of these:

1) src / test123.txt

2) FirstJavaProgram / src / test123.txt

我不确定在你的情况下哪一个会好。

I am not sure which one will be fine in your case.

这篇关于使用Intellij idea IDE读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆