Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. static void Array(){
  2. File archivo = null;
  3. FileReader fr = null;
  4. BufferedReader br = null;
  5.  
  6. try {
  7. // Apertura del fichero y creacion de BufferedReader para poder
  8. // hacer una lectura comoda (disponer del metodo readLine()).
  9. archivo = new File ("datos.txt");
  10. fr = new FileReader (archivo);
  11. br = new BufferedReader(fr);
  12.  
  13. // Lectura del fichero
  14. String linea;
  15. while((linea=br.readLine())!=null)
  16. String[] campos = linea.split(" ");
  17. for(int i=0;i<campos.length;i++){
  18. System.out.println(campos[i]);
  19. }
  20. }
  21. catch(Exception e){
  22. e.printStackTrace();
  23. }finally{
  24. // En el finally cerramos el fichero, para asegurarnos
  25. // que se cierra tanto si todo va bien como si salta
  26. // una excepcion.
  27. try{
  28. if( null != fr ){
  29. fr.close();
  30. }
  31. }catch (Exception e2){
  32. e2.printStackTrace();
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement