Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final String START_NAME_FILE = "nombre_del_archivo";
- private static final String FILE_EXTENSION = ".txt";
- String fileName = START_NAME_FILE +"_"+formatCalToday+ FILE_EXTENSION;
- String credentialsUserName = Nombre_usuario
- String credentialsPassword = Pass_usuario
- String pathShared = ip/ruta/equipo/remoto
- //extraemos la ip
- String ip = pathShared.substring(2,(pathShared.substring(2)).indexOf("\") + 2);
- //creating txt file
- File file = new File(pathShared+fileName);
- FileWriter writer = new FileWriter(file);
- //escribiendo en el archivo, Writing the file
- BufferedWriter out = new BufferedWriter(writer);
- PrintWriter salida2 = new PrintWriter(out);
- if ( file.canRead() ) {
- Debug.logInfo("Se inicia el proceso de grabacion", module);
- }
- String fileContent = "Aquí Escribiremos cualquier cosa";
- salida2.write(fileContent);
- salida2.println();
- salida2.flush();
- salida2.close();
- out.close();
- String successMessage = " se genero el archivo ""+fileName+"" en la siguiente ruta ""+pathShared+""";
- // commandConnect, lo que hace usando la linea de comando de windows
- // ingresa con la ip, el usuario y la contraseña del servidor que esta compartiendo
- String commandConnect = "cmd /c net use \\" + ip + "\ipc$ /user:" + credentialsUserName + " " + credentialsPassword;
- // He expects the process to finalize
- try {
- Process process = Runtime.getRuntime().exec(commandConnect);
- int exitCode = process.waitFor();
- if (exitCode != 0) {
- throw new IOException("Command exited with " + exitCode);
- }
- } catch (Exception ex) {
- ex.getMessage();
- }
- String commandDisconnect = "cmd /c net use \\" + ip + "\ipc$ /d";
- // He expects the process to finalize
- try {
- Process process = Runtime.getRuntime().exec(commandDisconnect);
- int exitCode = process.waitFor();
- if (exitCode != 0) {
- throw new IOException("Command exited with " + exitCode);
- }
- } catch (Exception ex) {
- ex.getMessage();
- }
Add Comment
Please, Sign In to add comment