패키지 파일; import java.io.file;/** * 폴더의 특정 형식으로 모든 파일을 출력 * @author hasee * */public static void main (String [] args) {gettxtname ( "d :/a", ". jpg"); } public static void getTxtName (문자열 path, 문자열 접미사) {// 파일 객체가 파일인지 폴더인지 // 파일 객체 파일을 작성하는지 여부를 변호합니다. f = 새 파일 (path); // if (f.isfile ()) {if (f.getName (). endSwith (wiffix)) {system.out.println (f.getabsolutepath ()); }} else {// 폴더 파일을 전송합니다 [] files = f.listfiles (); if (files! = null && files.length> 0) {// (파일 : 파일) {getTxtName (file.getAbsolutepath (), 접미사)에 대한 파일 또는 폴더를 재귀 적으로 얻습니다. }}}}}}2. 폴더 아래의 특정 형식으로 모든 파일을 삭제합니다.
패키지 파일; import java.io.file; public class demo3 {public static void main (string [] args) {// todo 자동 생성 메소드 스터브 삭제 ( "d :/a", ". jpg"); } public static void delete (문자열 경로, 문자열 접미사) {file f = 새 파일 (path); if (f.isfile ()) {if (f.getName (). endSwith (wiffix)) {System.out.println (f.getAbsolutepath ()+"성공적으로 삭제"); f.delete (); }} else {file [] files = f.listfiles (); if (files! = null && files.length> 0) {for (파일 : files) {delete (file.getabsolutepath (), 접미사); }}}}}}요약
위는 편집기가 소개 한 Java 구현 출력 폴더의 특정 형식으로 모든 파일의 예제 코드입니다. 모든 사람에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨 주시면 편집자가 제 시간에 모든 사람에게 답장을 드리겠습니다. Wulin.com 웹 사이트를 지원해 주셔서 대단히 감사합니다!