【发布时间】:2022-11-22 01:50:34
【问题描述】:
我想在 BufferedReader 中添加路径而不是文件名? 我想使用该路径,因为我希望代码在该特定文件夹中获取名称为“audit”的任何文件。
所以我目前正在使用下面的这种方法,但它只有在我添加绝对路径时才有效。
`
public static void main(String[] args)
throws IOException {
List<String> stngFile = new ArrayList<String>();
BufferedReader bfredr = new BufferedReader(new FileReader
("file path"));
String text = bfredr.readLine();
while (text != null) {
stngFile.add(text);
text = bfredr.readLine();
}
bfredr.close();
String[] array = stngFile.toArray(new String[0]);
Arrays.toString(array);
for (String eachstring : array) {
System.out.println(eachstring);
}
}
`
我是编程新手,非常感谢任何帮助。提前致谢。
【问题讨论】:
-
您需要循环打开与您的模式匹配的每个文件。
标签: java path bufferedreader