Estoy tratando de obtener la ruta de un archivo.txt y al cargar el archivo y guardarlo en la misma ubicación pero con otro nombre "respuestas.txt" con las operaciones que realizo.
Dándome un resultado así. https://i.stack.imgur.com/RI4Xn.png
Y no encuentro la forma para que se guarde solamente con el nombre "respuestas.txt"
Espero alguien me pueda apoyar, gracias.
public class Peticion {
public static void main(String[] args) {
Http peticion = new Http();
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
FileNameExtensionFilter txt = new FileNameExtensionFilter("Archivos de texto", "txt","text");
fileChooser.setFileFilter(txt);
fileChooser.showOpenDialog(fileChooser);
String ruta = fileChooser.getSelectedFile().getAbsolutePath();
String nombreArchivo = "respuestas.txt";
File file = new File(ruta+nombreArchivo);
BufferedWriter bw = null;
String line = "";
String cad = "";
try {
Scanner input = new Scanner(new File(ruta));
while (input.hasNextLine()) {
line = input.nextLine();
cad += line + "\n" + peticion.getHTTP(line) + "\n\n";
}
if(file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
bw = new BufferedWriter(fw);
bw.write(cad);
bw.close();
input.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}