- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 Kotlin Android 应用程序中有以下 FileFilter:
fileArray = fileDirectory.listFiles { file, filename ->
file.length() > 0 && filename.matches(fileMatcherRegex)
}
file.length() > 0
比如说,
file.length() > 999999999999
,它会过滤掉所有文件,因此正在测试过滤器的 length() 元素。它只是没有产生我理解的结果。
最佳答案
方法listFiles
期望一个带有两个参数的 lambda,它基于 SAM conversion从 FilenameFilter
上的这个方法界面:
/**
* Tests if a specified file should be included in a file list.
*
* @param dir the directory in which the file was found.
* @param name the name of the file.
* @return <code>true</code> if and only if the name should be
* included in the file list; <code>false</code> otherwise.
*/
boolean accept(File dir, String name);
file.length()
正在检查
fileDirectory.length()
而不是文件的长度。
val fileArray = fileDirectory.listFiles { directory, filename ->
directory.length() > 0 && filename.matches(fileMatcherRegex)
}
FileFilter
接口(interface)是:
/**
* Tests whether or not the specified abstract pathname should be
* included in a pathname list.
*
* @param pathname The abstract pathname to be tested
* @return <code>true</code> if and only if <code>pathname</code>
* should be included
*/
boolean accept(File pathname);
val fileArray = fileDirectory.listFiles { file ->
file.length() > 0 && file.name.matches(fileMatcherRegex)
}
关于android - 这个 Kotlin FileFilter 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52564713/
我正在尝试创建一个文件过滤器,它只允许用户打开包含特定文件的目录。用例是这些目录是工作区,内部有一个名为 smart.workspace 的文件。 目前我的过滤器如下... class SMARTWo
我正在尝试找到一个 java.io.FileFilter 的实现,它理解如下模式:"**/*.xml", "src/**/*.java”等 不知道有没有package可以提供这样的filter(com
所以我只想列出指定目录中的目录。我尝试了 FileFilter 和 FilenameFilter。两者都不适合我,因为它们还包括文件。但是不知何故,SO 上的其他人对此没有问题。 java versi
我有一个包含几个 .txt 文件的目录。让我们说 hi.txt hello.txt hello_test.txt test.txt 在 VBA 中使用文件对话框,如何过滤以在下拉列表中仅显示“*tes
我最终使用 Eng. 的方法在 JFileChooser 的 JList 和 JComboBoxes 中自定义了选择颜色。福阿德建议here public void customizeJFileCho
我想向用户显示一个 FileChooser,他只能选择 .csv 文件,但他可以浏览文件系统以找到他想要的 .csv。通读http://download.oracle.com/javase/tutor
在我的项目中,我使用 JavaFX FileChooser 让用户保存文件。我注意到一个错误,其中具有指定文件过滤器的文件在 Linux 系统上总是保存为 .txt。从另一个 stackoverflo
我正在使用一个小型 Java 工具来根据一组文件扩展名获取一组文件,我在使用 listFiles() 和使用 continue; 之间争论不休,当我遇到一个错误的文件时,与使用自定义 FileFilt
我的 Kotlin Android 应用程序中有以下 FileFilter: fileArray = fileDirectory.listFiles { file, filename -> fil
Eclipse 显示两个错误: JFileChooser 类型中的 addChoosableFileFilter 方法不适用于参数 类型不匹配:无法从 FileNameExtensionFilter
当我执行这段代码时,我遇到了这个奇怪的问题: cdrFiles = dir.list(filter); System.out.println("cdrFiles length: " + cdrFile
我正在用java编写一个图表编辑器。该应用程序可以选择导出为各种标准图像格式,例如 .jpg、.png 等。当用户单击"file"->“导出”时,您会得到一个 JFileChooser,其中包含许多
我将简要解释我正在发生的事情,然后提供一些我的代码。 我有一个小型 GUI,我可以在 JComboBox 上选择一个选项,然后单击一个按钮,打开一个 JFileChooser,该按钮应根据 JComb
我试图扩展我发现的教程 here关于创建一个简单的文件浏览器。我想添加一个 FileFilter 以仅查看音频文件。但是,除了我在 String 数组中定义的文件类型之外,我仍然看到其他文件类型。感谢
下面是我的代码,通过单击按钮打开 JFileChooser。我创建了一个过滤器,只允许选择 .jpg 文件,但我的代码没有按预期工作。所有类型的文件都显示在 JFileChooser 对话框中。部分代
我想要一个有 2 个选项的文件过滤器,一个显示所有文件,另一个显示特定扩展名。 具体的扩展应该是默认选择的那个。 我两次使用相同的 JFileChooser,第一次显示 .fas 文件,第二次显示 .
大家下午好 我有一个 javax.swing.JFileChooser 的实例我添加了一些可选的 javax.swing.FileFilter使用 addChoosableFileFilter . 然
我有以下 FileFilter 代码: final FileFilter directoryFilter = new FileFilter() @Override public boo
我正在编写一个简单的程序,以递归方式列出目录中的文件 .class。 最初我这样编码: public class Parsing{ public static void main(String
我正在用 Java 编写图表编辑器。此应用程序可以选择导出为各种标准图像格式,例如 .jpg、.png 等。当用户单击文件 -> 导出时,您会得到一个 JFileChooser,其中有许多 FileF
我是一名优秀的程序员,十分优秀!