0
点赞
收藏
分享

微信扫一扫

将查询结果写入到文件


public TableDataInfo list(OctAttachmentFile octAttachmentFile) throws IOException {
        File f=new File("d:\\test.txt");//写入的文件
        if(!f.exists()){
            f.createNewFile();
        }
        octAttachmentFile.setStatus(1L);
        List<OctAttachmentFile> list = octAttachmentFileService.selectOctAttachmentFileList(octAttachmentFile);
        String prefixPath="E:\\tomact8\\webapps\\oct-attachment\\upload\\upload\\";
        int i=0;
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(f))) {
        for(OctAttachmentFile octAttachmentFile1:list){
            File file=new File(prefixPath+octAttachmentFile1.getFilePath());
            if(!file.exists()){
                System.out.println("文件不存在,主键id="+octAttachmentFile1.getId());
                writer.write(octAttachmentFile1.getId()+":"+octAttachmentFile1.getFilePath());
                writer.newLine();
                i++;
            }
        }
        } catch (IOException e) {
            logger.error("e={}",e);
        }
        System.out.println("总的数量为:"+i);
        return getDataTable(list);
    }

举报

相关推荐

0 条评论