嘿傢伙即時通訊發民的應用程序讀取目錄和子目錄和文件,所以這個工作完全如何顯示不同勢線在同一個JLabel在Java中
/*
* 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));
}
,在標籤「劇目」它讓我看到的問題,最後一個我想它SHO當我的每一個人像防病毒軟件掃描你的文件時一樣,你會看到它掃描的是什麼,我們可以做到這一點?
一般情況下,你可以使用HTML格式設置應用到文本,對於[示例](http://stackoverflow.com/questions/29550524/jlabel-with-multiple -lines-and-alignment-the-right/29551195#29551195)和[示例](http://stackoverflow.com/questions/14737810/jlabel-show-longer-text-as-multiple-lines/14738193# 14738193) – MadProgrammer
@MadProgrammer取決於[''Document'' type](http://docs.oracle.com/javase/7/docs/api/javax/swing/text/html/HTMLDocument.html),但是的,基本上你是對的 –
@BinkanSalaryman沒有,簡單得多,那只是' This
is
some
text' - 自從Java 1.3開始工作:) – MadProgrammer