package foro;
import javax.swing.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
/**
* @author rub´n
*/
public class TestFileChooser {
public TestFileChooser() {
}
public void EscribirEnArchivo
(final String texto
) { //Async manera [b]sucia[/b]
//getDest() obtiene el path absoluto + se concatena con el nombre del archivo
final Path directorio = Paths.get(getDest().toString() + "/TuNombreDeArchivo.bat");
final StringBuilder sb = new StringBuilder();
try(final BufferedWriter bW
= Files.
newBufferedWriter(directorio,StandardOpenOption.
CREATE)) { bW.write(sb.append(texto).toString());
e.printStackTrace();
}
}).start();
}
//Obtener destino
private Path getDest() {
jFileChooser.
setFileSelectionMode(JFileChooser.
DIRECTORIES_ONLY); //jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); en este caso a ti te sirve escojer el directorio
final int opc = jFileChooser.showOpenDialog(null);
if (!(opc == 0)) {
}
return jFileChooser.getSelectedFile().toPath();
}
private static String getTexto
() { final StringBuilder sb = new StringBuilder();
return sb.append("@echo off\r\n")
.append("msg * Hola SrTrp\r\n")
.append(":end")
.toString();
}
public static void main
(String... _0x72
) { try {
} catch (Exception ex
){ex.
printStackTrace();} final TestFileChooser testFileChooser = new TestFileChooser();
testFileChooser.EscribirEnArchivo(getTexto());
}
}