writeUTF
public final void writeUTF(String str)
throws IOException
- Writes a string to the file using UTF-8 encoding in a machine-independent
manner.
First, two bytes are written to the file, starting at the current file
pointer, as if by the writeShort method giving the number of
bytes to follow. This value is the number of bytes actually written out, not
the length of the string. Following the length, each character of the string
is output, in sequence, using the UTF-8 encoding for each character.
-
- Specified by:
writeUTF
in interface DataOutput
- Parameters:
str - a string to be written.
- Throws:
IOException
- if an I/O error occurs.
Ou seja, primeiro dois bytes sao escritos para a posicao corrente do
arquivo, logo ap�s a sua string ser�, gravada no arquivo. note que o tamanho do
arquivo ser� 7 ou seja os seus 5 caracteres mais os dois bytes que o metodo
grava
Um Abraco
Isa�as Cristiano Barroso
----- Original Message -----
Sent: Thursday, February 07, 2002 11:10
AM
Subject: [java-list] Problemas ao
escrever em arquivos
Pessoal, tenho uma aplica��o em Java q grava em
um arquivo de log os seus principais eventos. Para isto estou utilizando as
classes File e RandomAccessFile, por�m estou tendo problemas ao escrever pois,
por exemplo, se eu invoco o m�todo:
File infoArq = new
File("/home/aryjr/javas/EJB/newsletter/log");
// Caso o
arquivo n�o exista eu o criarei
if (!infoArq.exists())
infoArq.createNewFile();
RandomAccessFile arq = new
RandomAccessFile(infoArq,"rw");
arq.writeUTF("Teste");
arq.close();
Ele escreve a string "Teste" com alguns outros
caracteres:
"^S�Teste"
Algu�m poderia me dar alguma
sugest�o???
Valeu!!!!!