在java中1小时后更新csv文件

在java中1小时后更新csv文件,java,netbeans-8,Java,Netbeans 8,我用java制作了一个线程,它在1小时的时间间隔后连续检查windows中最近的项目,并生成一个包含所有最近项目的.csv文件。此外,我有最近项目中所有文件的访问时间和文件夹位置。现在我想做的是,随着最近的项目不断更新,所以如果最近的项目中有一个新文件,它应该附加在已经制作的csv文件的末尾,但我被困在这里,不知道如何做,请帮助我,我的代码在这里 /* * To change this license header, choose License Headers in Project Prop

我用java制作了一个线程,它在1小时的时间间隔后连续检查windows中最近的项目,并生成一个包含所有最近项目的.csv文件。此外,我有最近项目中所有文件的访问时间和文件夹位置。现在我想做的是,随着最近的项目不断更新,所以如果最近的项目中有一个新文件,它应该附加在已经制作的csv文件的末尾,但我被困在这里,不知道如何做,请帮助我,我的代码在这里

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package record;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import static java.sql.DriverManager.println;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.awt.shell.ShellFolder;

/**
 *
 * @author zeeshan
 */
public class Record 
{
    static String user=System.getProperty("user.name");
    static String path1="C:\\Users\\"+user+"\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\";
    static String path2="C:\\Users\\Fa16Rcs028\\Dropbox\\Spring 17\\Special Topics In HCI\\Sir Aimal Project\\output.csv";
    static PrintWriter pw;
    static StringBuilder sb = new StringBuilder();
    public void createcsv()throws IOException
    {


            File directory = new File(path1);
            File[] fList = directory.listFiles();
            pw = new PrintWriter(new File(path2));

            sb.append("File/Folder Name");
            sb.append(',');
            sb.append("Access Time");
            sb.append(',');
            sb.append("File Location");
            sb.append('\n');
            for (int i=0;i<fList.length;i++)
            {
                String filename=fList[i].getName();
                String actualfilename=filename.replace(".lnk", "");
                ShellFolder sf = ShellFolder.getShellFolder(fList[i]);
                ShellFolder target = sf.getLinkLocation();
                if (target != null)
                {
                    Path p = Paths.get(path1+filename);
                    BasicFileAttributes view= Files.getFileAttributeView(p, BasicFileAttributeView.class).readAttributes();
                    FileTime fileTime=view.creationTime();
                    sb.append(actualfilename);
                    sb.append(',');
                    sb.append(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format((fileTime.toMillis())));
                    sb.append(',');
                    sb.append(target.getAbsolutePath());
                    sb.append('\n');



                }




            }
            pw.write(sb.toString());
            pw.close();

    }
    public static class maintainrecord extends Thread
    {
        @Override
        public void run()
        {
            File directory = new File(path1);
            File[] fList = directory.listFiles();
            for (File fList1 : fList) {
                try {
                    String filename = fList1.getName();
                    String actualfilename=filename.replace(".lnk", "");
                    Path p = Paths.get(path1+filename);
                    BasicFileAttributes view= Files.getFileAttributeView(p, BasicFileAttributeView.class).readAttributes();
                    FileTime fileTime=view.creationTime();
                    String time=new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format((fileTime.toMillis())).toString();
                    String line = "";
                    String cvsSplitBy = ",";
                    try (BufferedReader br = new BufferedReader(new FileReader(path2)))
                    {
                        while ((line = br.readLine()) != null)
                        {
                            String[] record = line.split(cvsSplitBy);
                            String name=record[0];
                            String checktime=record[1];
                            if(actualfilename.equals(name) && !time.equals(checktime))
                            {
                                br.close();
                                pw = new PrintWriter(new File(path2));
                                sb.append(actualfilename);
                                sb.append(',');
                                sb.append(actualfilename);
                                sb.append(',');
                            }
                        }

                    }
                }catch (IOException ex)
                {
                    Logger.getLogger(Record.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }

    public static void main(String[] args) throws IOException 
    {
        Record r=new Record();
        r.createcsv();
        Thread zeeshan=new Thread(new  maintainrecord());
        zeeshan.start();
        Thread.sleep(600000);


    }



}
/*
*要更改此许可证标题,请在“项目属性”中选择“许可证标题”。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
包装记录;
导入java.io.BufferedReader;
导入java.io.BufferedWriter;
导入java.io.File;
导入java.io.FileReader;
导入java.io.FileWriter;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.nio.file.Files;
导入java.nio.file.Path;
导入java.nio.file.path;
导入java.nio.file.attribute.BasicFileAttributeView;
导入java.nio.file.attribute.BasicFileAttributes;
导入java.nio.file.attribute.FileTime;
导入静态java.sql.DriverManager.println;
导入java.text.DateFormat;
导入java.text.simpleDataFormat;
导入java.util.Date;
导入java.util.logging.Level;
导入java.util.logging.Logger;
导入sun.awt.shell.shell文件夹;
/**
*
*@作者泽山
*/
公开课记录
{
静态字符串user=System.getProperty(“user.name”);
静态字符串path1=“C:\\Users\\”+user+“\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\”;
静态字符串path2=“C:\\Users\\Fa16Rcs028\\Dropbox\\Spring 17\\HCI\\Sir Aimal Project\\output.csv中的特殊主题”;
静态打印机;
静态StringBuilder sb=新StringBuilder();
public void createcsv()引发IOException
{
文件目录=新文件(路径1);
File[]fList=directory.listFiles();
pw=新的PrintWriter(新文件(路径2));
sb.追加(“文件/文件夹名称”);
某人附加(“,”);
sb.追加(“访问时间”);
某人附加(“,”);
sb.append(“文件位置”);
sb.追加('\n');

对于(int i=0;i什么是问题/问题/问题?我想要的是,如果最近的项目中有一些新文件,我只想在excel工作表中附加该文件,而不是整个最近的项目文件,因为它已经写入excel工作表@jonzarate什么是最近的项目?它包含什么?它在哪里?excel存储什么?这是什么
file
你提到过吗?如果你想得到适当的帮助,你必须更加努力并仔细解释一切。最近的项目是windows操作系统中的一个文件夹,它保存用户最近访问的所有文件的记录。@Jonzarate有什么问题/问题/问题?我想知道的是,最近的项目中是否有一些新文件我想应用只在excel工作表中结束该文件,而不是整个最近的项目文件,因为它已经写入excel工作表@jonzarate。最近的项目是什么?它包含什么?它在哪里?excel存储什么?你提到的
文件是什么?如果你想得到适当的帮助,你必须更加努力并仔细地解释一切。“最近使用的项目”是windows操作系统中的一个文件夹,用于记录用户最近访问的所有文件。@JonZarate