Tag: filesystems

如何查看新内容的文件并检索该内容

我有一个名为foo.txt的文件。 该文件包含一些文本。 我想实现以下function: 我启动程序 写一些文件(例如添加一行: new string in foo.txt ) 我想获得此文件的新内容。 你能澄清这个问题的最佳解决方案吗? 此外,我想解决相关问题:如果我修改foo.txt我想看到差异。 我在Java中找到的最接近的工具是WatchService但如果我理解正确,这个工具只能检测文件系统上发生的事件类型(创建文件或删除或修改)。

如何在Java 7中可移植地获取文件存储的块大小?

我查看了java.nio.file.attribute.Attributes和java.nio.file.FileStore ,但找不到发现磁盘文件块大小的方法。

Java:如何递归获取所有子目录?

在调试延迟时间外的递归函数之前:是否有一个获取子目录的命令? giveMeSubDirs(downToPath) ? // WARNING: RECURSION out of bound or too much data public HashSet getAllDirs(String path) { HashSet checkedDirs = new HashSet(); HashSet allDirs = new HashSet(); String startingPath = path; File fileThing = new File(path); FileObject fileObject = new FileObject(fileThing); for (FileObject dir : getDirsInDir(path)) { // SUBDIR while ( !checkedDirs.contains(dir) && !(getDirsInDir(dir.getFile().getParent()).size() […]

ZipFileSystemProvider无法识别JIMFS

我有一个从字节数组在jimfs (内存文件系统中的google)中创建的zip文件。 尝试使用ZipMemoryFileSystem打开该文件时,出现无法识别提供程序的错误。 我的代码如下: public static void test(byte[] document) { try { try (FileSystem memoryFileSystem = Jimfs.newFileSystem(Configuration.unix())) { Files.write(memoryFileSystem.getPath(“/file.zip”), document); URI uri = URI.create(“jar:” + memoryFileSystem.getPath(“/file.zip”).toUri()); Map env = Collections.singletonMap(“create”, “false”); try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) { //do something } catch (Exception e) { e.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } […]