الأمثلة على النحو التالي:
public static void copyfolder (String srcfolder ، string destfolder) يلقي ioException {long startTime = system.currentTimeMillis () ؛ المسار النهائي srcpath = paths.get (srcfolder) ؛ // قم بإنشاء مستوى آخر هنا لحل مشكلة عدم وجود Shell Final Path DestPath = paths.get (destfolder ، srcpath.tofile (). getName ()) ؛ // تحقق مما إذا كان المجلد المصدر موجودًا إذا (files.notexists (srcpath)) {system.err.println ("المجلد المصدر غير موجود") ؛ System.exit (1) ؛ } // إذا لم يكن الدليل الهدف موجودًا ، فقم بإنشاء if (files.notexists (destPath)) {files.createdIrectories (destPath) ؛ }. SimpleFileVisitor <Path> () {// المسؤول يسمى أيضًا معالجة مجلد خاصة ، والتي لم يتم استخدامها هنا // publicvisitresult previsitdirectory (path dir ، // basicfileattributes سمات) BasicFileAttributes rewors IoException }}) ؛ ioException ("المجلد غير موجود!") ؛ Override / / معالجة الدليل العام postvisitord (path dir ، ioexception Main (String [] args) يلقي ioException {// copyfolder ("c: // user // administrator // desktop // 111" ، "d: // compression // level 1 // level 2") ؛إذا كان لديك أي أسئلة ، يرجى طرحها ، شكرًا لك!
المثال أعلاه لنسخ وحذف المجلدات في فئة مسارات وملفات JDK1.7 هو المحتوى بالكامل المشترك من قبل المحرر. آمل أن يعطيك مرجعًا وآمل أن تتمكن من دعم wulin.com أكثر.