- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下类(class),文件夹中的文件类似于(xyz_1_071_basefiles_03272_30087.txt。)
并且我粗体的位置我只想选择该部分并对其进行排序,如果该值不是像下面的示例那样添加
这样就好了
10000
10001
10002
10003
10004
但是如果像下面这样
10000
10001
10003
10004
然后我想显示这两个文件数字 10001、10003,因为这两个数字之间缺少 10002,下面是我到目前为止所做的代码。
public loopMe() {
File dir = new File(path);
File[] directoryListing = dir.listFiles();
if (directoryListing != null) {
for (File child : directoryListing) {
//System.out.println(child.getName());
String filename = child.getName();
String filename1 = filename.substring(24,30);
System.out.println(filename1);
}
} else {
}
}
最佳答案
更新以包含从文件名获取数字的方法:
Integer sequenceNo = Integer.parseInt(filename.split("_")[4]);
这将在 _
字符上分割文件名,然后检索第四个元素。
在现有代码的基础上,将提取的文件名部分转换为整数(如上所示),将它们全部放入列表中并对其进行排序,有点像这样:
List<Integer> filenames = new ArrayList<>();
for (File child : directoryListing) {
String filename = child.getName();
String filename1 = filename.substring(24,30);
filenames.add(Integer.parseInt(filename1));
}
Collections.sort(filenames);
现在循环列表,查看当前条目是否存在 - 1 > 1 差异,如下所示(未经测试):
int previousInSequence = filenames.get(0);
for (Integer currentSequence : filenames) {
if (currentSequence - previousInSequence > 1) {
// you have missing files
// currentSequence - previousInSequence will tell you how many
}
}
关于java - java中如何从文件名中选取特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28068864/
在下面的代码中,我想不必添加undefined作为filteredDevice的类型注解。我认为一个被过滤的设备不应该是未定义的,因为我过滤掉了未定义的设备。 但是如果我删除 undefined类型注
我有一个 UIButton,其文本来自服务器。按钮的宽度是固定的。我想要的是,如果按钮的文本超过按钮的宽度,文本应该在按钮内选取框。如果文本适合按钮宽度,则不应有选取框效果。 我点击了一些链接(one
我正在从头开始实现 webgl 选取,并决定走 GLSL 路线,而不是光线相交测试。 所以我将整个场景渲染到一个单独的帧缓冲区中,为每个对象分配一个唯一的颜色,该颜色作为统一变量传递给片段着色器。当场
例如,我有包含多个对象的数组, var arr = ["a", "b", "c", "d"]; 我想要的是从该数组中选取 2 个随机对象,例如“a”和“c”,并将这 2 个对象推送到另一个数组中,例如
我是一名优秀的程序员,十分优秀!