00001
00002
00003
00004
00005
00006
00007
00008
00014 package org.sci2s.eamhco;
00015
00016
00017 import java.io.*;
00018 import java.util.*;
00019
00020 public class Fichero {
00026 public static String leeFichero(String nombreFichero) {
00027 String cadena = "";
00028 try {
00029 FileInputStream fis = new FileInputStream(nombreFichero);
00030 byte[] leido = new byte[4096];
00031 int bytesLeidos = 0;
00032 while (bytesLeidos != -1) {
00033 bytesLeidos = fis.read(leido);
00034 if (bytesLeidos != -1) {
00035 cadena += new String(leido, 0, bytesLeidos);
00036 }
00037 }
00038 fis.close();
00039 }
00040 catch (IOException e) {
00041 e.printStackTrace();
00042 System.exit( -1);
00043 }
00044 return cadena;
00045 }
00046
00047 public static void escribeFichero(String nombreFichero, String cadena) {
00048 try {
00049 FileOutputStream f = new FileOutputStream(nombreFichero);
00050 DataOutputStream fis = new DataOutputStream((OutputStream) f);
00051 fis.writeBytes(cadena);
00052 fis.close();
00053 }
00054 catch (IOException e) {
00055 e.printStackTrace();
00056 System.exit( -1);
00057 }
00058 }
00059
00060 public static void AnadirtoFichero(String nombreFichero, String cadena) {
00061 try {
00062 RandomAccessFile fis = new RandomAccessFile(nombreFichero, "rw");
00063 fis.seek(fis.length());
00064 fis.writeBytes(cadena);
00065 fis.close();
00066 }
00067 catch (IOException e) {
00068 e.printStackTrace();
00069 System.exit( -1);
00070 }
00071 }
00072 }