相关疑难解决方法(0)

避免 Java 8 Files.walk(..) 终止原因 ( java.nio.file.AccessDeniedException )

我正在使用Java 8 Files.walk(..)来计算.mp3文件夹中包含的文件以及其中的所有文件夹。换句话说,我正在访问文件树的所有级别。

当我得到java.nio.file.AccessDeniedExceptionStream关闭,我不希望这种行为。我需要它来忽略或打印异常并继续计算文件。下面是我使用的代码:):

   /**
     * Count files in a directory (including files in all sub
     * directories)
     * 
     * @param directory
     *        the directory to start in
     * @return the total number of files
     */
    public int countFiles(File dir) {
        if (dir.exists())
            try (Stream<Path> paths = Files.walk(Paths.get(dir.getPath()), FileVisitOption.FOLLOW_LINKS)) {
                return (int) paths.filter(path -> {

                    // i am using something different here but i changed
                    // it just for the purpose of …
Run Code Online (Sandbox Code Playgroud)

java nio access-denied

5
推荐指数
1
解决办法
7998
查看次数

在Haxe中查找并​​列出文件夹中的所有文件/文件夹

这个问题与这些问题基本相同

但是有没有办法在Haxe的sys目标平台上执行相同的操作,而无需运行ls/ dirvia sys.io.Process和解析结果?

haxe

4
推荐指数
1
解决办法
175
查看次数

递归读取文件夹中的所有文件Java

我需要编写一个程序来读取文件夹路径stdin及其所有子文件夹,然后根据其扩展名打印出文件数。

编译如下:

java Summary -r <path>

输出需要如下所示:

txt:
  number of files: 5
  combined size: 1202131
  largest file: 729224
  smallest file: 12323
pdf:
  number of files: 2
  etc...
Run Code Online (Sandbox Code Playgroud)

有人可以帮我吗?我不知道如何处理它。

java inputstream filereader

3
推荐指数
1
解决办法
1万
查看次数

具有绝对路径的Java FileNotFoundException - 无法读取或执行,但文件存在

我确信这已经得到了解答,但十种不同的策略在这个问题上没有奏效.

如果我使用C:\ Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt作为文件的绝对路径,则IDEA无法从此路径读取或执行.如果我采用相同的路径并将其粘贴到Windows资源管理器中,它将立即执行.我不想专注于工作目录,因为这个文件作为程序的配置文件工作,但用反斜杠替换斜杠不起作用,绝对路径仍然将我带到文件,但IDEA没有启动.

我的智慧结束了.

 public static String generateFileName(String folder){

    String filename = "";
    List<String> hashtags = new ArrayList<>();
    String instructions_file =         "C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt";

    //does not return true-true, but can launch file on windows explorer..
    System.out.println("FILE EXIST AND EXECUTE?" + new File(instructions_file).getAbsoluteFile().canRead() +" "+new File(instructions_file).getAbsoluteFile().canExecute());

    System.out.println(new File(instructions_file).getAbsoluteFile());
    //C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Trees\instructions.txt

    BufferedReader br = null;

    try {

        String sCurrentLine;

        br = new BufferedReader(new FileReader(new File(instructions_file).getAbsoluteFile()));
Run Code Online (Sandbox Code Playgroud)

编辑 用正斜杠替换反斜杠后,阅读器仍无法正确读取或执行该文件.

日志:字符串打印:C:/Users/Anny/Dropbox/SocialMediaOcto/instructions/Bees/instructions.txt

  java.io.FileNotFoundException:    C:\Users\Anny\Dropbox\SocialMediaOcto\instructions\Bees\instructions.txt (The system cannot find the file specified)
Run Code Online (Sandbox Code Playgroud)

java filenotfoundexception file-not-found fileutils

2
推荐指数
1
解决办法
737
查看次数

如何使用Java从文件夹中的所有文件中一一读取数据?

如何使用Java从文件夹中的所有文件(一个一个)中读取数据?

此代码仅返回文件名,我正在寻找更深入的搜索:

File folder = new File("/home/user_name/Downloads/textfiles/");
File[] listOfFiles = folder.listFiles();

for (File file : listOfFiles) {
    if (file.isFile()) {
        System.out.println(file.getName());
    }
}
Run Code Online (Sandbox Code Playgroud)

java

2
推荐指数
1
解决办法
8218
查看次数

如何从java中的文件夹中读取多个csv文件?

我想从 java 中的文件夹中读取多个 csv 文件。所有文件都是 csv 并且格式相同,但问题是我得到的文件夹的路径只是这样。

> conf/files
Run Code Online (Sandbox Code Playgroud)

这是我所有 csv 文件所在的文件夹。我有一个程序,当给出路径时读取单个文件,例如

> conf/files/sample.csv
Run Code Online (Sandbox Code Playgroud)

如果我能得到像这样的文件名列表,我可以阅读所有这些。请帮忙...

java csv file-io file

1
推荐指数
1
解决办法
2万
查看次数