即使在使用Java的文件中添加新文件时,如何在不更改顺序的情况下列出目录中的所有文件夹?当我运行程序时,它将进入一个带有“未检查”注释的无限循环,我输入该注释是为了查看它是否正在检查文件。
try
{
BufferedWriter bufferedWriter = null;
bufferedWriter = new BufferedWriter(new FileWriter("d://my.txt"));
BufferedReader br = new BufferedReader(new FileReader("d://my.txt"));
int i=1;
File f=new File("D:/Moviezzz");
File[] fi=f.listFiles();
for(File fil:fi)
{
if(!fil.isHidden() && (fil.isDirectory() || fil.isFile()))
{
int s=i++;
String files = fil.getName();
String thisLine;
while(null != (thisLine="\t"+br.readLine()))
{
String exist[]=thisLine.split("\t");
//ensure that it is already written in file
if(exist[0].equals(files))
{
System.out.println("Checked");
}
//ensure that it is not written in file
else
{
System.out.println("Not Checked");
}
}
bufferedWriter.write(s+"\t"+files);
bufferedWriter.newLine();
bufferedWriter.flush();
System.out.print("yes");
// bufferedWriter.write(s+" "+files);
}
br.close();
//Construct the BufferedWriter object
System.out.println("Succ");
}
}
catch(Exception ex)
{
System.out.println("failed");
}