Advertisement
acrogenesis

Grabar.java

May 6th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package com.brackeen.javagamebook.grabar;
  2.  
  3. import java.io.*;
  4.  
  5. public class Grabar{
  6.     private int mapaTexto;
  7.     private String nombreArchivo = "Grabar.txt";
  8.  
  9.     public void touchFile() throws IOException{
  10.         File f = new File(nombreArchivo);
  11.         if (!f.isFile())
  12.             f.createNewFile();
  13.     }
  14.  
  15.     public int readFile() throws IOException{
  16.         try{
  17.             touchFile();
  18.         } catch(IOException ex){
  19.             ex.printStackTrace();
  20.         }
  21.        
  22.         BufferedReader fileIn = new BufferedReader(new FileReader(nombreArchivo));
  23.         String dato = fileIn.readLine();
  24.         int mapaTexto = Integer.parseInt(dato);
  25.         fileIn.close();
  26.         return mapaTexto;
  27.     }
  28.  
  29.     public void writeFile(int n) throws IOException{
  30.         try{
  31.             touchFile();
  32.         } catch(IOException ex){
  33.             ex.printStackTrace();
  34.         }
  35.         PrintWriter fileOut = new PrintWriter(new FileWriter(nombreArchivo));
  36.         fileOut.println(n);
  37.         fileOut.close();
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement