zwfzwfa 2022-04-01 10:56 采纳率: 71.4%
浏览 37
已结题

读取csv文件最后两行数据,然后取出文件名称,下面是CSV文件

若依框架
2021/3/22 8:13:21 8:14:25 2DSRT10MCS PD/OTA Production 5333548 1D1140 SPL 47 47 0 NA 202671 amd_5333548_5333548_SPL_2DSRT10MCS_081425.dat OPN Data is not changed
2021/3/22 8:17:55 8:21:30 2DSRT10MCS PD/OTA Production 5333548 1D1140 SPL 83 83 0 NA 202671 amd_5333548_5333548_RUB_2DSRT10MCS_082130.dat OPN Data is not changed
2021/3/22 8:30:55 8:33:29 2DSRT10MCS PD/OTA Production 5333528 1D1140 SPL 79 79 0 NA 202671 amd_5333528_5333528_SPL_2DSRT10MCS_083329.dat OPN Data is not changed
2021/3/22 8:35:30 8:40:12 2DSRT10MCS PD/OTA Production 5333528 1D1140 SPL 81 81 0 NA 202671 amd_5333528_5333528_RUB_2DSRT10MCS_084012.dat OPN Data is not changed
2021/3/22 8:40:54 8:42:19 2DSRT10MCS PD/OTA Production 5324068 1D1140 SPL 11 11 0 NA 202671 amd_5324068_5324068_SPL_2DSRT10MCS_084219.dat OPN Data is not changed
2021/3/22 8:44:32 8:48:14 2DSRT10MCS PD/OTA Production 5324068 1D1140 SPL 149 149 0 NA 202671 amd_5324068_5324068_RUB_2DSRT10MCS_084814.dat OPN Data is not changed
2021/3/22 8:56:48 8:58:10 2DSRT10MCS PD/OTA Production 4643937 1D1140 SPL 20 20 0 NA 202671 amd_4643937_5319631_SPL_2DSRT10MCS_085810.dat OPN Data is not changed
2021/3/22 8:59:55 9:03:27 2DSRT10MCS PD/OTA Production 4643937 1D1140 SPL 2 2 0 NA 202671 amd_4643937_5319631_RUB_2DSRT10MCS_090327.dat OPN Data is not changed
2021/3/22 9:03:43 9:05:13 2DSRT10MCS PD/OTA Production 5333909 1D1140 SPL 38 38 0 NA 202671 amd_5333909_5333909_SPL_2DSRT10MCS_090513.dat OPN Data is not changed
2021/3/22 9:07:37 9:12:47 2DSRT10MCS PD/OTA Production 5333909 1D1140 SPL 94 94 0 NA 202671 amd_5333909_5333909_RUB_2DSRT10MCS_091247.dat OPN Data is not changed
2021/3/22 9:24:40 9:26:13 2DSRT10MCS PD/OTA Production 4651647 1D1140 SPL 15 15 0 NA 202671 amd_4651647_5331561_SPL_2DSRT10MCS_092613.dat OPN Data is not changed
2021/3/22 9:27:53 9:30:50 2DSRT10MCS PD/OTA Production 4651647 1D1140 SPL 91 91 0 NA 202671 amd_4651647_5331561_RUB_2DSRT10MCS_093050.dat OPN Data is not changed
2021/3/22 10:15:55 10:17:24 2DSRT10MCS PD/OTA Production 4524110 GF4094 SPL 3 3 0 NA 202671 amd_4524110_5051548_SPL_2DSRT10MCS_101724.dat OPN Data is not changed
2021/3/22 10:19:26 10:23:16 2DSRT10MCS PD/OTA Production 4524110 GF4094 SPL 5 5 0 NA 202671 amd_4524110_5051548_RUB_2DSRT10MCS_102316.dat OPN Data is not changed
2021/3/22 10:36:40 10:38:21 2DSRT10MCS PD/OTA Production 5323087 1D1140 SPL 62 62 0 NA 202671 amd_5323087_5323087_SPL_2DSRT10MCS_103821.dat OPN Data is not changed
2021/3/22 10:40:04 10:43:29 2DSRT10MCS PD/OTA Production 5323087 1D1140 SPL 35 35 0 NA 202671 amd_5323087_5323087_RUB_2DSRT10MCS_104329.dat OPN Data is not changed
2021/3/22 10:44:18 10:46:20 2DSRT10MCS PD/OTA Production 5333968 1D1140 SPL 70 70 0 NA 202671 amd_5333968_5333968_SPL_2DSRT10MCS_104620.dat OPN Data is not changed
2021/3/22 10:48:04 10:50:30 2DSRT10MCS PD/OTA Production 5333968 1D1140 SPL 11 11 0 NA 202671 amd_5333968_5333968_RUB_2DSRT10MCS_105030.dat OPN Data is not changed
2021/3/22 12:11:55 12:14:47 2DSRT10MCS PD/OTA Production 5326638 1D1140 SPL 107 107 0 NA 202671 amd_5326638_5326638_SPL_2DSRT10MCS_121447.dat OPN Data is not changed
2021/3/22 12:17:58 12:21:22 2DSRT10MCS PD/OTA Production 5326638 1D1140 SPL 53 53 0 NA 202671 amd_5326638_5326638_RUB_2DSRT10MCS_122122.dat OPN Data is not changed
2021/3/22 12:21:39 12:24:30 2DSRT10MCS PD/OTA Production 5332386 1D1140 SPL 145 145 0 NA 202671 amd_5332386_5332386_SPL_2DSRT10MCS_122430.dat OPN Data is not changed
2021/3/22 12:26:45 12:29:05 2DSRT10MCS PD/OTA Production 5332386 1D1140 SPL 15 15 0 NA 202671 amd_5332386_5332386_RUB_2DSRT10MCS_122905.dat OPN Data is not changed
2021/3/22 12:33:45 12:35:17 2DSRT10MCS PD/OTA Production 5334105 1D1140 SPL 64 64 0 NA 202671 amd_5334105_5334105_SPL_2DSRT10MCS_123517.dat OPN Data is not changed
2021/3/22 12:37:16 12:40:17 2DSRT10MCS PD/OTA Production 5334105 1D1140 SPL 92 92 0 NA 202671 amd_5334105_5334105_RUB_2DSRT10MCS_124017.dat OPN Data is not changed
2021/3/22 12:41:30 12:43:50 2DSRT10MCS PD/OTA Production 5334327 1D1140 SPL 120 120 0 NA 202671 amd_5334327_5334327_SPL_2DSRT10MCS_124350.dat OPN Data is not changed
2021/3/22 12:45:35 12:48:58 2DSRT10MCS PD/OTA Production 5334327 1D1140 SPL 40 40 0 NA 202671 amd_5334327_5334327_RUB_2DSRT10MCS_124858.dat OPN Data is not changed
2021/3/22 13:05:28 13:08:16 2DSRT10MCS PD/OTA Production 5333978 1D1140 SPL 147 147 0 NA 202671 amd_5333978_5333978_SPL_2DSRT10MCS_130816.dat OPN Data is not changed
2021/3/22 13:10:29 13:13:38 2DSRT10MCS PD/OTA Production 5333978 1D1140 SPL 13 13 0 NA 202671 amd_5333978_5333978_RUB_2DSRT10MCS_131338.dat OPN Data is not changed
2021/3/22 13:14:32 13:16:15 2DSRT10MCS PD/OTA Production 5331309 BN1140 SPL 61 61 0 NA 202671 amd_5331309_5331309_SPL_2DSRT10MCS_131615.dat OPN Data is not changed
2021/3/22 13:18:04 13:21:08 2DSRT10MCS PD/OTA Production 5331309 BN1140 SPL 99 99 0 NA 202671 amd_5331309_5331309_RUB_2DSRT10MCS_132108.dat OPN Data is not changed
2021/3/22 13:22:17 13:24:09 2DSRT10MCS PD/OTA Production 5333237 1D1140 SPL 68 68 0 NA 202671 amd_5333237_5333237_SPL_2DSRT10MCS_132409.dat OPN Data is not changed
2021/3/22 13:25:52 13:31:18 2DSRT10MCS PD/OTA Production 5333237 1D1140 SPL 92 92 0 NA 202671 amd_5333237_5333237_RUB_2DSRT10MCS_133118.dat OPN Data is not changed
2021/3/22 16:09:43 16:12:13 2DSRT10MCS PD/OTA Production 5334307 1D1140 SPL 52 52 0 NA 202671 amd_5334307_5334307_SPL_2DSRT10MCS_161213.dat OPN Data is not changed
2021/3/22 16:14:17 16:19:03 2DSRT10MCS PD/OTA Production 5334307 1D1140 SPL 81 81 0 NA 202671 amd_5334307_5334307_RUB_2DSRT10MCS_161903.dat OPN Data is not changed
2021/3/22 17:40:22 17:42:23 2DSRT10MCS PD/OTA Production 5334892 1D1140 SPL 11 11 0 NA 202671 amd_5334892_5334892_SPL_2DSRT10MCS_174223.dat OPN Data is not changed
2021/3/22 17:44:27 17:48:26 2DSRT10MCS PD/OTA Production 5334892 1D1140 SPL 134 134 0 NA 202671 amd_5334892_5334892_RUB_2DSRT10MCS_174825.dat OPN Data is not changed

可在下面的代码修改

String fileName="";
// 创建 reader
try (BufferedReader br = Files.newBufferedReader(Paths.get("users.csv"))) {
    // CSV文件的分隔符
    String DELIMITER = ",";
    // 按行读取
    String line;
    while ((line = br.readLine()) != null) {
        // 分割
        String[] columns = line.split(DELIMITER);
       fileName=columns[0];
    }
} catch (IOException ex) {
    ex.printStackTrace();
}
System.out.println("最后一行文件名称:"+fileName);

amd_5334892_5334892_SPL_2DSRT10MCS_174223.dat
amd_5334892_5334892_RUB_2DSRT10MCS_174825.dat

  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2022-04-02 12:06
    关注

    这种写法更好理解一点

           String fileName="";
            // 创建 reader
            List<String> list = new ArrayList();
            BufferedReader br =null;
            try {
                br=Files.newBufferedReader(Paths.get("users.csv"));
                // CSV文件的分隔符
                String DELIMITER = ",";
                // 按行读取
                String line;
                while ((line = br.readLine()) != null) {
                    // 分割
                    String[] columns = line.split(DELIMITER);
                    fileName=columns[14];
                    list.add(fileName);
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            System.out.println("最后一行文件名称:"+list.get(list.size()-1));
            System.out.println("最后第二行文件名称:"+list.get(list.size()-2));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 4月11日
  • 已采纳回答 4月3日
  • 创建了问题 4月1日

悬赏问题

  • ¥15 海洋可控源和大地电磁一维联合反演
  • ¥15 MFC多文档程序获取视图指针问题
  • ¥20 解体如何编写程序还有运行结果截图
  • ¥15 如何把matlabR2023遗传算法工具箱里面的各类选项对应的代码调出来呢?
  • ¥30 MDIGetActive() 获取活动view
  • ¥15 有数据,如何安装使用CLIP模型检索图片
  • ¥15 lingo代码报错无法运行,如何解决,如果能解决请提供能够运行的lingo代码
  • ¥100 读取 IMU BNO080 数据
  • ¥15 基于RTKLIB框架写的精密单点定位-AR
  • ¥15 PFENet的预训练权重