I am creating a program that lists the contents of a file, the problem that when I initialize my String array I have an error that is not recognized. This is the code:
File origen = new File("TEXTO.TXT");
InputStream in = new FileInputStream(origen);
FileOutputStream destino = new FileOutputStream(new File("COPIADO.TXT"));
ObjectOutputStream oOS = new ObjectOutputStream(destino);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
oOS.write(buf, 0, len);
}
in.close();
oOS.close();
String[] destino1 = origen.list();
for (int i = 0; i<destino1.length; i++) {
System.out.println(destino1[i]);
}
Error
Exception in thread "main" java.lang.NullPointerException
at ficheros.Ficheros.main(Ficheros.java:37)
for (int i = 0; i<destino1.length; i++) {
System.out.println(destino1[i]);
}