Cô giáo cho đề bài này mà e làm hoài ko đúng ! A e xem e lỗi chỗ nào chỉ giúp e với ! Thanks a e nhìu lắm !
Đề :
[HIDE]Viết chương trình tìm kiếm tất cả các tập tin ( file ) có phần mở rộng là .java trong một thư mục do người dùng nhập vào đường dẫn[/HIDE]
Code của mình :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import java.io.File;
/**
*
* @author CP201103-H12
*/
class thi {
/**
* @param args the command line arguments
*/
String java;
public thi(String java) {
this.java = "." + java;
}
public boolean accept (File dir, String fName){
return fName.endsWith(java);
}
public static void main(String[] args) {
String dirName = "d:/";
File fileObj = new File ("d:/");
thi filterObj = new thi("java");
String[] fileName = fileObj.list();
System.out.println("" + fileName.length);
for(int i=0; i < fileName.length; i++) {
System.out.println(fileName);
}
}
}
[/HIDE]
Đề :
[HIDE]Viết chương trình tìm kiếm tất cả các tập tin ( file ) có phần mở rộng là .java trong một thư mục do người dùng nhập vào đường dẫn[/HIDE]
Code của mình :
[HIDE]/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
import java.io.File;
/**
*
* @author CP201103-H12
*/
class thi {
/**
* @param args the command line arguments
*/
String java;
public thi(String java) {
this.java = "." + java;
}
public boolean accept (File dir, String fName){
return fName.endsWith(java);
}
public static void main(String[] args) {
String dirName = "d:/";
File fileObj = new File ("d:/");
thi filterObj = new thi("java");
String[] fileName = fileObj.list();
System.out.println("" + fileName.length);
for(int i=0; i < fileName.length; i++) {
System.out.println(fileName);
}
}
}
[/HIDE]