problemas con devolver un vector de string
Hola amigo: alguien me podia decir donde esta el herror en este metodo que devuelve un vector de String:
public String[] getArchivos()
{
File f1 = new File(dirName);
if (f1.isDirectory())
{
String s[] = f1.list();
String [] videos= new String[this.getCantidadVideos()];
int j=0;
for (int i = 0; i < s.length; i++)
{
if(s[i].endsWith(".txt")==true)
{
videos[j]=s[i];
j++;
}
}
s=null;
}
return videos;
}
public String[] getArchivos()
{
File f1 = new File(dirName);
if (f1.isDirectory())
{
String s[] = f1.list();
String [] videos= new String[this.getCantidadVideos()];
int j=0;
for (int i = 0; i < s.length; i++)
{
if(s[i].endsWith(".txt")==true)
{
videos[j]=s[i];
j++;
}
}
s=null;
}
return videos;
}
En principio, aunque no dices cuál es el problema. Aparentemente es que la variable videos debe estar declarada fuera del if (f1.isDirectory()), luego dentro le podrás dar valor.
Por otro lado, la comparación
if(s[i].endsWith(".txt")==true)
la puedes cambiar por
if(s[i].endsWith(".txt")).
Saludos.
Por otro lado, la comparación
if(s[i].endsWith(".txt")==true)
la puedes cambiar por
if(s[i].endsWith(".txt")).
Saludos.
