Galera…
Seguinte, tenho um sistema rodando com seus pacotes, quero gravar e ler um arquivo dentro desse pacote para quando gerar o .jar esse arquivo esteja junto e seja criado sempre dentro do pacote.
minha estrutura eh…/Projeto/src/pacotes
Quero gerar o arquivo.txt dentro do pacote bd…Ficaria assim /Projeto/src/pacotes/bd, nesse arquivo .txt vou gravar o endereco ip do meu servidor mysql.
Estou tentando assim.
//cria arquivo.txt
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(!enderecoIp.getText().isEmpty()){
try{
File ferEndIpServerSql = new File("bd/mysql.txt");
if(!ferEndIpServerSql.exists()){
ferEndIpServerSql.createNewFile();
}else{
ferEndIpServerSql.delete();
ferEndIpServerSql.createNewFile();
FileWriter arquivoTxt = new FileWriter(ferEndIpServerSql, true);
PrintWriter linhasTxt = new PrintWriter(arquivoTxt);
linhasTxt.print(enderecoIp.getText());
arquivoTxt.close();
}
this.dispose();
}catch(IOException e){
//
}
}else{
JOptionPane.showMessageDialog(null, "Informe o endereço do Servidor MySQL.",
"Server Address",
JOptionPane.INFORMATION_MESSAGE);
enderecoIp.requestFocus();
}
}
//le arquivo txt
public void setIp(File file) throws IOException{
java.io.InputStream is = new FileInputStream(file);
Scanner sc = new Scanner(is);
if(sc.hasNext()){
String enderecoIp = sc.nextLine();
this.host = enderecoIp;
}else{
new AbreDialog().abreDialog(new ServidorSQL(null, true));
}
is.close();
sc.close();
}
//invoca metodo para setar ip
con2.setIp(new File("bd/mysql.txt"));
Ainda nao tive resultados, qquer ajuda sera bem vinda. Obrigado. !