Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.brackeen.javagamebook.grabar;
- import java.io.*;
- public class Grabar{
- private int mapaTexto;
- private String nombreArchivo = "Grabar.txt";
- public void touchFile() throws IOException{
- File f = new File(nombreArchivo);
- if (!f.isFile())
- f.createNewFile();
- }
- public int readFile() throws IOException{
- try{
- touchFile();
- } catch(IOException ex){
- ex.printStackTrace();
- }
- BufferedReader fileIn = new BufferedReader(new FileReader(nombreArchivo));
- String dato = fileIn.readLine();
- int mapaTexto = Integer.parseInt(dato);
- fileIn.close();
- return mapaTexto;
- }
- public void writeFile(int n) throws IOException{
- try{
- touchFile();
- } catch(IOException ex){
- ex.printStackTrace();
- }
- PrintWriter fileOut = new PrintWriter(new FileWriter(nombreArchivo));
- fileOut.println(n);
- fileOut.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement