JAVA问题总结之28–读取某目录下所有文件
package java9231;
import java.io.File;
public class forReadNFile {
public static void main(String[] args) {
// TODO Auto-generated method stub
File f1=new File("file100");
for(int i=0;i<f1.listFiles().length;i++){
System.out.println(f1.listFiles()[i]);}
}
}
结果:
file100\0_0 Guide.ppt
file100\1.txt
file100\10.txt
file100\100.txt
file100\11.txt
file100\12.txt
file100\13.txt
file100\14.txt
file100\15.txt
file100\16.txt
file100\17.txt
file100\18.txt
file100\19.txt
file100\2.txt
file100\20.txt
file100\21.txt
file100\22.txt
file100\23.txt
file100\24.txt
file100\25.txt
file100\26.txt
file100\27.txt
file100\28.txt
file100\29.txt
file100\3.txt
file100\30.txt
file100\31.txt
file100\32.txt
file100\33.txt
file100\34.txt
file100\35.txt
file100\36.txt
file100\37.txt
file100\38.txt
file100\39.txt
file100\4.txt
file100\40.txt
file100\41.txt
file100\42.txt
file100\43.txt
file100\44.txt
file100\45.txt
file100\46.txt
file100\47.txt
file100\48.txt
file100\49.txt
file100\5.txt
file100\50.txt
file100\51.txt
file100\52.txt
file100\53.txt
file100\54.txt
file100\55.txt
file100\56.txt
file100\57.txt
file100\58.txt
file100\59.txt
file100\6.txt
file100\60.txt
file100\61.txt
file100\62.txt
file100\63.txt
file100\64.txt
file100\65.txt
file100\66.txt
file100\67.txt
file100\68.txt
file100\69.txt
file100\7.txt
file100\70.txt
file100\71.txt
file100\72.txt
file100\73.txt
file100\74.txt
file100\75.txt
file100\76.txt
file100\77.txt
file100\78.txt
file100\79.txt
file100\8.txt
file100\80.txt
file100\81.txt
file100\82.txt
file100\83.txt
file100\84.txt
file100\85.txt
file100\86.txt
file100\87.txt
file100\88.txt
file100\89.txt
file100\9.txt
file100\90.txt
file100\91.txt
file100\92.txt
file100\93.txt
file100\94.txt
file100\95.txt
file100\96.txt
file100\97.txt
file100\98.txt
file100\99.txt