Home>

Given a method, a sheet with values ​​of the Path type comes into it (files from the directory that need to be archived) When trying to read it, an exception appears that such a file does not exist This is the line in the code - try (BufferedInputStream bis= new BufferedInputStream (new FileInputStream (temp.toFile ()))) What could be the reason? A sheet with 1346 records of the Path type comes to the file.

public static void packFiles (List <
Path >
 sources, File target) {
        int count= 0;
        try (ZipOutputStream zip= new ZipOutputStream (new BufferedOutputStream (new FileOutputStream (target)))) {
            while (sources.size ()!= count) {
             Path temp= sources.get (count ++);
                ZipEntry entry= new ZipEntry (String.valueOf (temp));
                zip.putNextEntry (entry);
                try (BufferedInputStream bis= new BufferedInputStream (new FileInputStream (temp.toFile ()))) {** THIS IS THE PLACE! **
                    zip.write (bis.readAllBytes ());
                }
                zip.closeEntry ();
            }
        } catch (Exception e) {
            e.printStackTrace ();
        }
    }

Why did they convert to Path? Didn't work last time?

default locale2021-02-23 07:38:36

And so, please provide complete information about the error: error type, message (literally, not in your own words), stack trace. Also, determine the file on which the error occurs, check if it exists.

default locale2021-02-23 07:40:16

Fill in this information in the question. Print the full path to the file (temp.toFile (). GetAbsolutePath ()) to the console and check if it is there

default locale2021-02-23 08:05:42

If you just output (temp.toAbsolutePath ())?

default locale2021-02-23 08:13:07

What does "same error" mean? If we write System.out.println (temp.toAbsolutePath ()) which path is printed? Is there a file in there?

default locale2021-02-23 09:08:26
  • Answer # 1

    useFiles.walkif you need files.

    Thanks, I already use it in a method that returns a filtered list

    Terasan2021-02-23 09:07:31