Guest User

Untitled

a guest
Jan 3rd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. private static final String START_NAME_FILE = "nombre_del_archivo";
  2. private static final String FILE_EXTENSION = ".txt";
  3.  
  4.  
  5. String fileName = START_NAME_FILE +"_"+formatCalToday+ FILE_EXTENSION;
  6. String credentialsUserName = Nombre_usuario
  7. String credentialsPassword = Pass_usuario
  8. String pathShared = ip/ruta/equipo/remoto
  9. //extraemos la ip
  10. String ip = pathShared.substring(2,(pathShared.substring(2)).indexOf("\") + 2);
  11.  
  12. //creating txt file
  13. File file = new File(pathShared+fileName);
  14. FileWriter writer = new FileWriter(file);
  15.  
  16. //escribiendo en el archivo, Writing the file
  17. BufferedWriter out = new BufferedWriter(writer);
  18. PrintWriter salida2 = new PrintWriter(out);
  19.  
  20. if ( file.canRead() ) {
  21. Debug.logInfo("Se inicia el proceso de grabacion", module);
  22. }
  23.  
  24.  
  25. String fileContent = "Aquí Escribiremos cualquier cosa";
  26. salida2.write(fileContent);
  27. salida2.println();
  28.  
  29.  
  30. salida2.flush();
  31. salida2.close();
  32. out.close();
  33.  
  34. String successMessage = " se genero el archivo ""+fileName+"" en la siguiente ruta ""+pathShared+""";
  35.  
  36. // commandConnect, lo que hace usando la linea de comando de windows
  37. // ingresa con la ip, el usuario y la contraseña del servidor que esta compartiendo
  38. String commandConnect = "cmd /c net use \\" + ip + "\ipc$ /user:" + credentialsUserName + " " + credentialsPassword;
  39.  
  40. // He expects the process to finalize
  41. try {
  42. Process process = Runtime.getRuntime().exec(commandConnect);
  43. int exitCode = process.waitFor();
  44. if (exitCode != 0) {
  45. throw new IOException("Command exited with " + exitCode);
  46. }
  47. } catch (Exception ex) {
  48. ex.getMessage();
  49. }
  50.  
  51. String commandDisconnect = "cmd /c net use \\" + ip + "\ipc$ /d";
  52. // He expects the process to finalize
  53. try {
  54. Process process = Runtime.getRuntime().exec(commandDisconnect);
  55. int exitCode = process.waitFor();
  56. if (exitCode != 0) {
  57. throw new IOException("Command exited with " + exitCode);
  58. }
  59. } catch (Exception ex) {
  60. ex.getMessage();
  61. }
Add Comment
Please, Sign In to add comment