Ver Mensaje Individual
  #2 (permalink)  
Antiguo 02/01/2006, 15:53
Avatar de dogduck
dogduck
 
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
Re:while not EOF...

try {
File inputFile = new File("original.txt");
File outputFile = new File("outagain.txt");
FileInputStream fis = new FileInputStream(inputFile);
FileOutputStream fos = new FileOutputStream(outputFile);
int c;

while ((c = fis.read()) != -1) {
//lee byte a byte de fis y lo vuelca en fos
fos.write(c);
}
fis.close();
fos.close
} catch (FileNotFoundException e) {
System.err.println("FileStreamsTest: " + e);
} catch (IOException e) {
// excepción más genérica de entrada / salida
System.err.println("FileStreamsTest: " + e);
}
------------------------------------------------------
Otra forma que he encontrado :
import java.io.*;

public class LecturaFichero {
// Throw exceptions to console:
public static void main(String[] args)
throws IOException {
String s, s2 = new String();
// 1. Reading input by lines:

BufferedReader in = new BufferedReader(
new FileReader("fichero.txt"));
//leemos de linea a linea ,
// para hacerlo de caracter a caracter seria :
// while(( n=in.read())!=-1){c=(char)n; s2+=c+"\n"}

while((s = in.readLine())!= null){
s2 += s + "\n";
}
in.close();
System.out.print(s2);
}
}

Última edición por dogduck; 02/01/2006 a las 16:00