如何在Java中指定文件路径? [英] How to specify filepath in java?

查看:398
本文介绍了如何在Java中指定文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 Debian Linux创建了一个Java应用程序。现在,我希望该应用程序读取放置在指定该应用程序的jar文件的目录中的文件。那么在文件对象的自变量中要指定什么呢?

I have created a java application for "Debian Linux." Now I want that that application reads a file placed in the directory where the jar file of that application is specified. So what to specify at the argument of the File Object?

File fileToBeReaded = new File(...);

要作为上述语句的参数指定的内容,以指定相对文件路径来表示jar文件所在的路径

What to specify as argument for the above statement to specify relative filepath representing the path where the jar file of the application has been placed?

推荐答案

如果您知道文件名,当然就是

If you know the name of the file, of course it's simply

new File("./myFileName")

如果您不知道名称,则可以使用File对象的list()方法获取当前目录中的文件列表,然后选择所需的文件。

If you don't know the name, you can use the File object's list() method to get a list of files in the current directory, and then pick the one you want.

这篇关于如何在Java中指定文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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