Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
Cómo resolver la excepción en el hilo "principal" java.lang.NullPointerException al copiar archivos/directorios

Tengo este ejemplo de código para copiar archivos y directorios de una ubicación a otra. Pero esta excepción sigue apareciendo cada vez que ejecuto el programa. ¿Alguien puede ayudarme a encontrar el error?

Excepción en el hilo "principal" java.lang.NullPointerException

 public void listFilesAndFilesSubDirectories(String directoryName) throws FileNotFoundException, IOException { File directory = new File(directoryName); //get all the files from a directory File[] fList = directory.listFiles(); for (File file : fList) { if (file.isFile()) { //System.out.println(file.getAbsolutePath()); System.out.println("File"); File source = new File("C:\\Users\\Core i3\\Desktop\\Check me\\" + file); File dest = new File("C:\\Users\\Core i3\\Desktop\\New folder"); System.out.println(source); InputStream is = null; OutputStream os = null; try { is = new FileInputStream(source); os = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } } finally { is.close(); os.close(); } } else if (file.isDirectory()) { listFilesAndFilesSubDirectories(file.getAbsolutePath()); System.out.println("Directory"); File source = new File("C:\\Users\\Core i3\\Desktop\\Check me\\" + file); File dest = new File("C:\\Users\\Core i3\\Desktop\\New folder"); InputStream is = null; OutputStream os = null; try { is = new FileInputStream(source); os = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = is.read(buffer)) > 0) { os.write(buffer, 0, length); } } finally { is.close(); os.close(); } } } }
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!