嘿,伙计们,我正在开发一个应用程序来读取目录、子目录和文件,这样就可以完美地工作了。
/*
* 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 avd;
import java.io.File;
/**
*
* @author USER
*/
public class arborescence {
private String initialpath = "";
private Boolean recursivePath = false;
public int filecount = 0;
public int dircount = 0;
/**
* Constructeur
* @param path chemin du répertoire
* @param subFolder analyse des sous dossiers
*/
public arborescence(String path, Boolean subFolder) {
super();
this.initialpath = path;
this.recursivePath = subFolder;
}
public void list() {
this.listDirectory(this.initialpath);
}
private void listDirectory(String dir) {
File file = new File(dir);
File[] files = file.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory() == true) {
System.out.println("Dossier: " + files[i].getAbsolutePath());
FirstWindow.lblRepertoire.setText(files[i].getAbsolutePath());
this.dircount++;
} else {
System.out.println(" Fichier: " + files[i].getName());
FirstWindow.lblFile.setText(files[i].getAbsolutePath());
this.filecount++;
}
if (files[i].isDirectory() == true && this.recursivePath == true) {
this.listDirectory(files[i].getAbsolutePath());
}
}
}
}
}
在主类中,我有以下内容:
public void scanfiles(){
String pathToExplore = fileName;
arborescence arbo = new arborescence(pathToExplore, true);
Long start = System.currentTimeMillis();
arbo.list();
System.out.println("----------");
System.out.println("Analyse de " + pathToExplore + " en " + (System.currentTimeMillis() - start) + " mses");
lbltime.setText(Integer.toString((int) (System.currentTimeMillis() - start)));
System.out.println(arbo.dircount + " dossiers");
lblCountRep.setText(Integer.toString(arbo.dircount));
System.out.println(arbo.filecount + " fichiers");
lblCountFiles.setText(Integer.toString(arbo.filecount));
}
这是我的相框
问题是,在标签“曲目”,它告诉我,最后一个,我想,它显示给我每一个喜欢,当反病毒扫描你的文件时,你看到它正在扫描什么,我们可以这样做吗?
发布于 2015-08-03 20:54:19
This就是一个这样做的例子。不确定你是否在寻找同样的东西。实际上html为你做了一些事情。
JLabel label = new JLabel("<html>First line and maybe second line</html>");
通过使用适当的布局使您的jlabel可伸缩。可能是网格袋布局。它应该能做到这一点。
https://stackoverflow.com/questions/31787600
复制相似问题