1
I have a String
which contains the file path, and I need to remove the characters that come after the last "/"
to the end of the string. Can anyone help me with this? ...
Example:
String comando = "C:/Users/Vinicius/Documents/NetBeansProjects/ProjetoORI/retiramarca.exe"
I want to erase the "retiramarca.exe"
caminho = pesquisaInfo.getText();
chave = recebeConfirme.getText();
caminhoInvertido = caminho.replace("\\", "/");
if (actionCommand.equals("Encrypt File")) {
String comando = "C:/Users/Vinicius/Documents/NetBeansProjects/ProjetoORI/inseremarca.exe " + chave + " " + caminhoInvertido;
try {
System.out.println(caminhoInvertido.getParentFile());
Runtime.getRuntime().exec("cmd.exe /C start " + comando);
} catch (IOException ex) {
}
System.out.println(actionCommand);
JOptionPane.showMessageDialog(null, "Arquivo criptografado");
You don’t need regex for that. Add the code there that you are using, there are no regex solutions to recover it.
– user28595
Not only does it not need regex, but it wouldn’t be the most appropriate, because what you want is to go to the previous folder. You should do as @Articuno indicated
– Isac
All life you catch an exception and don’t treat it properly, a fairy dies
– Jefferson Quesado