package Admin;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Esta clase permite escribir/leer el archivo de configuración.
*
* @author Urko
*
*/
public class FicheroConfig {
String contFich;
String delimiter = ",";
int i = 0;
String [] temp;
File archivo = new File ("config.ini");
FileReader fr;
BufferedReader br;
FileWriter fileOutput;
PrintWriter pw;
int tamx;
int tamy;
String URL;
int nPort;
String nBD;
public void cargarDatos(){
try {
fr = new FileReader(archivo);
br = new BufferedReader(fr);
contFich = br.readLine();
temp = contFich.split(delimiter);
} catch (FileNotFoundException e) {
System.out.println("File Not Found");
e.printStackTrace();
} catch (IOException e) {
System.out.println("FATAL ERROR");
e.printStackTrace();
} finally{
URL = temp[0];
nBD = temp[1];
nPort = Integer.valueOf(temp[2]);
tamy = Integer.valueOf(temp[3]);
tamx = Integer.valueOf(temp[4]);
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void guardarDatos(int tamx, int tamy, String URL, int nPort, String nBD) {
try{
fileOutput = new FileWriter (archivo);
pw = new PrintWriter(fileOutput);
pw.print(URL + "," + nBD + "," + nPort + "," + tamy + "," + tamx);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
pw.close();
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.