public
class DAO{private FileReader reader;
private BufferedReader input;
private BufferedWriter writer;
private PrintWriter print;
private String registroArchivo;
private File path;
private File file;
public
void escribirArchivoMemoriaExterna (String archivo, String registro)throws DAOException { try {abrirArchivoMemoriaExternaParaEscritura(archivo);
escribirArchivoMemoriaExterna(registro);
cerrarArchivoParaEscrituraMemoriaExterna(archivo);
}
catch (DAOException ux) { throw ux;}
catch (Exception ex) { throw new DAOException("Error de sistema");}
}
public void abrirArchivoMemoriaExternaParaEscritura(String archivo) throws DAOException { try { boolean sdDisponible = false; boolean sdAccesoEscritura = false;
String estado = Environment.getExternalStorageState();
if (estado.equals(Environment.MEDIA_MOUNTED)){
sdDisponible = true;
sdAccesoEscritura = true;
}else if (estado.equals(Environment.MEDIA_MOUNTED_READ_ONLY)){
sdDisponible = true;
sdAccesoEscritura = false;
}else {
sdDisponible = false;
sdAccesoEscritura = false;
}
if (sdDisponible && sdAccesoEscritura){
path= Environment.getExternalStorageDirectory();
file= new File(path.getAbsolutePath(), archivo);
writer= new BufferedWriter(new FileWriter(file));
print = new PrintWriter(writer);
}else{
throw new DAOException("No se puede abrir, para escritura, el archivo " + archivo);
}
}catch (Exception ex){
throw new DAOException("Error de sistema");
}
}
private boolean escribirArchivoMemoriaExterna(String registro) throws DAOException {
try {
print.println(registro);
} catch (Exception ex) {
throw new DAOException("Error al escribir en el archivo");
}
}
public void cerrarArchivoParaLecturaMemoriaExterna(String archivo) throws DAOException {
try {
if (input != null) {
input.close();
}
} catch (IOException e) {
throw new DAOException("No se puede cerrar el archivo " + archivo);
}
}
public void cerrarArchivoParaEscrituraMemoriaExterna(String archivo) throws DAOException {
try {
if (input != null) {
print.close();
}
} catch (Exception e) {
throw new DAOException("No se puede cerrar el archivo " + archivo);
}
}
}
--
Has recibido este mensaje porque estás suscrito al grupo "soloJ2ME" de Grupos de Google.
Para publicar una entrada en este grupo, envía un correo electrónico a solo...@googlegroups.com.
Para anular tu suscripción a este grupo, envía un correo electrónico a soloj2me+u...@googlegroups.com
Para tener acceso a más opciones, visita el grupo en http://groups.google.com/group/soloj2me?hl=es.