Buenas!
Boa tarde galera, estou com um problema.
Tenho uma JTree que lista nomes de arquivos de um diretório. Quando eu clico com o botão direito e seleciono a opção excluir/renomear no POP-UP menu não consigo excluir/renomear os arquivos.
Usei em todo o sistema a classe File para listar os arquivos. Isto pode estar gerando um lock? como faço para excluir este lock sem ter que alterar todo o sistema?
Abaixo os métodos de renomear e excluir.
private void aplica_renomear() {
try {
String nomeProjeto = ((DefaultMutableTreeNode) treepath_editando.getPath()[1]).toString();
String nomeTela = ((DefaultMutableTreeNode) treepath_editando.getPath()[2]).toString();
File origem = new File(getProjectPath(nomeProjeto) + File.separatorChar + nomeAntigoTela);
File destino = new File(getProjectPath(nomeProjeto) + File.separatorChar + nomeTela);
//tentativa frustrada
//OutputStream os = new FileOutputStream(origem);
//os.close();//tem q fechar o arquivo de origem para poder renomear
if (!origem.renameTo(destino)) {
System.out.println("não deu por algum motivo");
}
System.out.println("é para ter renomeado");
this.updateJTree();
nomeAntigoTela = null;
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void menu_excluir() {
treepath_editando = jtreeProjetos.getSelectionPath();
String nomeProjeto = ((DefaultMutableTreeNode) treepath_editando.getPath()[1]).toString();
String nomeTela = ((DefaultMutableTreeNode) treepath_editando.getPath()[2]).toString();
File arquivo_excluido = new File(getProjectPath(nomeProjeto) + File.separatorChar + nomeTela);
if (JOptionPane.showConfirmDialog(null, "Tem certeza de que deseja excluir o arquivo'" + nomeTela + "'?") == JOptionPane.OK_OPTION) {
arquivo_excluido.delete();
this.updateProject(nomeProjeto, new File(this.getProjectPath(nomeProjeto)));
}
treepath_editando = null;
nomeAntigoTela = null;
}
Obs.: O código ta simplificado para melhor entendimento.
vlw