stilovl 17 de mar. de 2020
arruma isso
for ( int i = 0 ; i < afile . length ; i ++ ) {
arquivos = afile [ i ] ;
novo = String . valueOf ( arquivos );
aqui vc deveria salvar o valor de “ novo ” em algum lugar , se não , ná proxima execução do laço o valor de “ novo ” será alterado . Por exemplo , na primeira execução do laço , o valor de “ novo ” é X , como a condição do laço ainda não retorna true ( i ainda é menor que afile . length ) ele vai iniciar o laço novamente , agora “ novo ” que valia X tem seu valor substituido por Y e o valor de X é perdido , após isso a condição do laço retorna true e sai do laço , dai faz a leitura somente de um arquivo . Um solução seria criar um Array de Strings [] e passar o mesmo indice de afile para esse array , assim salvando todos os “ novo ” , um em cada indice , e quando for fazer a leitura dos dados criar um laço for e passar todos os indices .
Albertassi88 17 de mar. de 2020
@stilovl esta dando erro…
for ( int i = 0 ; i < afile . length ; i ++ ) {
arquivos = afile [ i ] ;
String [] string = afile ;
novo = String . valueOf ( arquivos );
}
tentei dessa forma e não vai também…
File [] string ;
public String pdfLeitor () {
File arquivos = null ;
File file = new File ( "C:\\Users\\Ruben\\Desktop\\teste\\" );
File afile [] = file . listFiles ();
for ( int i = 0 ; i < afile . length ; i ++ ){
arquivos = afile [ i ] ;
string = afile ;
novo = String . valueOf ( string );
}
Albertassi88 17 de mar. de 2020
@stilovl consegue me ajudar?
stilovl 17 de mar. de 2020
String [] string = new String [ afile.length ] ;
for ( int i = 0 ; i < afile . length ; i ++ ) {
string [ i ] = afile [ i ] . toString ();
}
assim vc vai receber um diretorio em cada indice do array de strings, só não sei se seu codigo inteiro vai funcionar, não testei aqui.
Albertassi88 17 de mar. de 2020
@stilovl fiz dessa forma e ele continua me retornando só um conteúdo, aonde errei?
public String pdfLeitor () {
String [] string = null ;
String arquivos = null ;
File file = new File ( "C:\\Users\\Ruben\\Desktop\\teste\\" );
File afile [] = file . listFiles ();
for ( int i = 0 ; i < afile . length ; i ++ ) {
string = new String [ afile . length ] ;
string [ i ] = afile [ i ] . toString ();
arquivos = string [ i ] ;
}
String texto = null ;
for ( int i = 0 ; i < afile . length ; i ++ ) {
try {
PdfReader reader = new PdfReader ( arquivos );
texto = PdfTextExtractor . getTextFromPage ( reader , 1 );
} catch ( IOException e ) {
e . getStackTrace ();
}
}
return texto ;
}
stilovl 18 de mar. de 2020 1 like
String [] string = new String [ afile . length ] ;
for ( int i = 0 ; i < afile . length ; i ++ ){
string [ i ] = afile [ i ] . toString ();
}
Faça dessa forma , inicie o array de string fora do laço for , e não precisa passar a esse arquivos = string [ i ] não , dentro do segundo for vc passa PdfReader reader = new PdfReader ( string [ i ] );