java在哪里寻找文件? [英] Where does java look for files?

查看:130
本文介绍了java在哪里寻找文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用java读取文件:

 公共类测试{

public static void main(String [] args)throws IOException {

BufferedReader f = new BufferedReader(new FileReader(test.in));

// ...

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(test.out)));

// ...

}

}

1)test.in的位置应该在哪里? (src?bin????)



2)test.out在哪里?

解决方案

通常它是您正在执行的Java文件的确切位置。因此,如果您在C:\中使用Java文件并且在没有指定路径的情况下查找文件,它将在C:\中查找,输出文件也将在C:\

但是,如果您使用Netbeans之类的东西,则只需将文件放在特定项目的netbeans项目文件夹中即可。不在项目的源文件夹或bin文件夹中。


I'm trying to read a file in java:

Public class Test{

public static void main (String [] args) throws IOException {

BufferedReader f = new BufferedReader(new FileReader("test.in"));

//...

PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("test.out")));

//...                                 

}

}

1) Where should the location of "test.in" be? (src? bin? ???)

2) Where will "test.out" be located?

解决方案

Usually it's the exact location of where the Java file you are executing is. So if you use your Java file in C:\ and you look for a file without specifying a path, it will be in C:\ that it looks, and the output file will also be in C:\

If you are using something like Netbeans however, you just have to place the file in the netbeans project folder of your specific project. Not in the source or bin folders of your project.

这篇关于java在哪里寻找文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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