Java.nio - Loop interminável

1 resposta
S
CharsetDecoder decoder = Charset.forName("ISO-8859-1").newDecoder();
        FileChannel channel = new FileInputStream(pluginListFileName).getChannel();
        ByteBuffer buffer = ByteBuffer.allocateDirect(1024);
        CharBuffer pluginClassPath;
        CharBuffer pluginName;
        
        while (channel.read(buffer) != -1) {
            buffer.flip();
            pluginClassPath = decoder.decode(buffer);
            
            if (channel.read(buffer) != -1) {
                buffer.flip();
                pluginName = decoder.decode(buffer);
            }
      }

Quando este códgio atinge o while ele entra em um loop interminável, porquê?

Aliás, eu nunca entendi a diferença direito entre allocate(int) e allocateDirect(int) e quando usar um ou outro.

Obrigado.

1 Resposta

S

Pelo que vi parece que quando chamo o channel.read(buffer) a posição do buffer no arquivo não muda!

Criado 29 de junho de 2007
Ultima resposta 29 de jun. de 2007
Respostas 1
Participantes 1