File convertion not working inside a for loop
<p>I need to ftp download and convert a file to a string, this way:</p>

<pre><code>    public static boolean leArquivos(String inicioArquivo) {
    try {
        FTPClient mFtp = new FTPClient();
        mFtp.connect(FTPHOST, PORTA);
        mFtp.login(USUARIO, SENHA);
        FTPFile[] ftpFiles = mFtp.listFiles();
        int length = ftpFiles.length;
        for (int i = 0; i &lt; length; i++) {
            String nome = ftpFiles[i].getName();
            String[] itens = nome.split("_");
            boolean isFile = ftpFiles[i].isFile();
            String arquivo_id = itens[0];
            if (isFile &amp;&amp; (arquivo_id.equals(inicioArquivo))) {
                // the follow lines work if outside the for loop
                InputStream inStream = mFtp.retrieveFileStream(nome.toString());
                String arquivoLido = convertStreamToString(inStream);
                String[] arquivoLidoPartes = arquivoLido.split("#");
                Retorno.adicionaRegistro(nome, arquivoLidoPartes[0], arquivoLidoPartes[1], false);
            }
        }
    } catch(Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
</code></pre>

<p>This gonna read a 'inicioArquivo_anything.txt' and put into a string.
FTP and Registro.adicionaRegistro works fine.
If I move the 4 lines that are inside the 'if' to outside the 'for' loop, it works for a single file.
I need perform the action for several files.</p>

<p>Sorry about bad english (and bad Java too)...</p>

<p>EDIT</p>

<p>Worked this way</p>

<p>The convertion code:</p>

<pre><code>    private static String convertStreamToString(InputStream is, FTPClient mFtp) throws IOException { // added the client
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    StringBuilder total = new StringBuilder();
    String line;
    while ((line = r.readLine()) != null) {
        total.append(line);
    }
    r.close(); // close stream
    is.close(); // close stream
    mFtp.completePendingCommand(); 
    return total.toString();
}
</code></pre>

<p>And changed this:</p>

<pre><code>String arquivoLido = convertStreamToString(inStream, mFtp);
inStream.close();
</code></pre>
