entanglement 1 de out. de 2009
for ( String arq : lista )
{
arquivos . add ( new File ( "Jornais/" + arq ));
}
for ( File dir : arquivos ) {
System . out . println ( dir . getName ());
}
OCTAVIO 1 de out. de 2009
Agora ele tá repetindo o primeiro diretório.
FOLHA DE SAO PAULO (SP) 20080708
FOLHA DE SAO PAULO (SP) 20080708
O ESTADO DE SAO PAULO (SP) 20080708
public static void main ( String [] args ) {
List < File > arquivos = new ArrayList < File > ();
File f = new File ( "Jornais/" );
String [] lista = f . list ();
for ( String arq : lista )
{
arquivos . add ( new File ( "Jornais/" + arq ));
for ( File dirF : arquivos ) {
System . out . println ( dirF . getName ());
}
}
}
Tá quase hehe
OCTAVIO 1 de out. de 2009
Ah…agora consegui
Tava colocando o for dentro do for.
Fechei o primeiro e deu certo.
Obrigado entanglament =))
Abraço
falefernando 1 de out. de 2009
Segue um exemplo de aplicacao que fiz
public class Diretorio {
private String nome ;
private List diretorio ;
private List arquivo ;
public List < Diretorio > getDiretorio () {
return diretorio ;
}
public List < Arquivo > getArquivo () {
return arquivo ;
}
public void addArquivo ( Arquivo arquivo ) {
if ( this .arquivo == null ) {
this .arquivo = new ArrayList < Arquivo > () ;
}
this .arquivo .add ( arquivo ) ;
}
public String getNome () {
return nome ;
}
public void setNome ( String nome ) {
this .nome = nome ;
}
public void addDiretorio ( Diretorio diretorio ) {
if ( this .diretorio == null ) {
this .diretorio = new ArrayList < Diretorio > () ;
}
this .diretorio .add ( diretorio ) ;
}
}
import java.io.File;
public class ListaArquivosDiretorios {
private Diretorio diretorio ;
private String path ;
public ListaArquivosDiretorios ( String path , Diretorio diretorio ) {
this . diretorio = diretorio ;
this . path = path ;
listar ( new File ( this . path ), this . diretorio );
}
public void listar ( File path , Diretorio diretorio ) {
File [] files = path . listFiles ();
int indexDir = 0 ;
for ( int i = 0 ; i < files . length ; i ++ ) {
if ( files [ i ] . isFile ()) {
Arquivo arquivo = new Arquivo ();
arquivo . setNome ( files [ i ] . getName ());
String arquivoPath = files [ i ] . getPath ();
arquivo . setPath ( arquivoPath );
diretorio . addArquivo ( arquivo );
}
else {
Diretorio dirTemp = new Diretorio ();
dirTemp . setNome ( files [ i ] . getName ());
diretorio . addDiretorio ( dirTemp );
}
if ( files [ i ] . isDirectory ()){
listar ( files [ i ] , diretorio . getDiretorio (). get ( indexDir ));
indexDir ++ ;
}
}
}
public Diretorio getDiretorio () {
return this . diretorio ;
}
}