Originariamente inviato da energie
Salve ragazzi,ho qualche problema a leggere un carattere...questo perchè sto riscrivendo un programma che prima non utilizzava BufferedReader/writer ma il semplice dataoutputstream/inputstream,ho una variabile char chiamata c,al momento inizializzata a 0,quando usavo datainputstream per attribuire un nuovo valore a c,dato dall'utente scrivevo c=inzx.readChar();,ora però vorrei usare bufferedreader ma nn ho capito cosa devo utilizzare al posto di read char,ho visto lo javadoc e mi ha aiutato facendomi capire che bufferedreader non usa readChar ma read();...però non funziona...perchè scrivendo c=inzx.read(); compilando mi dice che trova un int ma ovviamente si aspetta un char...
Beh, lo dice la documentazione:

read

public int read()
throws IOException

Reads a single character.

Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Ti basta controllare se il valore di ritorno è diverso da -1 (eof) e quindi fare un cast a char!