Java mewujudkan file membaca dan menghapus folder
Paket Test.com; (String FilePath) melempar FileNotFoundException, IoException {file = file baru (FilePath); path = " + file.getPath ()); // System.out.println (" absolutePath = " + file.getAbsolutePath ()); tname ());} lain jika (file.isdirectory ()) {string [] FileList = file.list (); untuk (int i = 0; i <<<<<<< FILELIST.LENG; I ++)) {File Baca File (FilePath +"////" +FileList [i] ); )); {System.out.println ("ReadFile () Exception:" + e.getMessage ());} return true;} /*** hapus folder semua folder di bawah ini dan file* / /*public static boyan deleteFile (string delpath ) Melempar FileNoTFoundException, ioException {file file = file baru (delpath); ()) {System.out.println ("2"); // " + FileList [i]); if (! Delfile.isdirectory ()) {System.out.println (" path = " + deldpath ("); System.out.println ("AbsolutePath =" + Delfile.getabsolutePath (); ) {DeleteFile (Delpath + "//" + FileList [i]);}} file.delete (); ());} Return true;}*/ public static void main (string [] arts) {coba {c: // user/ /// desktop // skj_h25 positif // 004_rcag // 003_skj ");/ / DeleteFile ("d:/ file");} catch (filenotfoundeption ex) {} catch (ioException ex) {} stem.out.println (ok ");}}
Metode dua:
Paket OtherTudy; folder * */kelas publik testReadFile {/** * Jalur absolut webroot proyek * @return */string "// d:/$ {workspace}/$ {ProjectName}/webroot/web-inf/ kelas/"的路径 string path = this.getClass (). getResource ("/"). getPath (); // 从路径字符串 Keluarkan jalur rekayasa jalur = path.substring (1, path.indexof (" web -inf/class "); System.out.println (" Jalur Rekayasa: "+path); return path;}/*** @ @ @ @ @ @ param args*/public static void main (string [] args) {TestReamFile TRF = TestReamFile baru (); .printstacktrace ();}/** * All files under the specified path folder * @param filepath * @Return * @Throws filenotfffffff Oundexception * @throws IOEXception */Public Static Boolean Readallfile (String FilePath) Throws FilenotFoundException, IOEXCEPTION {File File = File baru (FilePath); ()); (File.isDirectory ()) {System.out.println ("/N Informasi daftar file folder:"); ++) {File Readful = FileList [i]; if (! ReadFile.isdirectory ()) {System.out.println ("/n/n/n/n/n/n/n/n/n/n/ N/n/n/n/n/n/n/n/n/n/n/n/t jalur relatif = " + readFile.getPath ()); System.out.println ("/t Path Absolute = " + readfile.getAbsolutePath ()); ));}}} {System.out.pr intln ("readfile () Exception:" + e.getMessage ());} return true;}/** * Hapus semua folder dan file di bawah folder * @param delpath * @Return * @throws filenotfoundeption * @throws ioException */public static boolean deleteFile (string delpath) melempar filenotfoundException, ioException {coba {file file = baru (delpath); .p Rintln ("1"); 0; ); isDirectory ()) {deleteFile (FileList [i] .getPath ());}} file.delete ();}}} (FileNotFoundException e) {system.out.println ("deleteFile ()" e.getMessage (); } Return true;}}
Di atas adalah semua isi artikel ini.