Guest User

Untitled

a guest
Oct 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public class procesos5 {
  2.  
  3.  
  4. public static void main(String[] args) {
  5.  
  6.  
  7. Runtime r = Runtime.getRuntime();
  8. Process p = null;
  9.  
  10. try{
  11. p= r.exec ("java Escritura");
  12.  
  13. OutputStream os = p.getOutputStream();
  14. os.write (args[0].getBytes());
  15.  
  16. os.flush();
  17.  
  18. InputStream is = p.getInputStream();
  19. BufferedReader br= new BufferedReader (new InputStreamReader( is) );
  20.  
  21.  
  22. String linea;
  23.  
  24. while((linea = br.readLine())!=null){
  25.  
  26. System.out.println(linea);
  27.  
  28. }//END WHILE
  29.  
  30. br.close();
  31.  
  32. }catch (Exception e) {
  33.  
  34. System.out.println ("Debes pasar un argumento");
  35. System.exit(-1);
  36.  
  37.  
  38. }
  39. try{
  40.  
  41. int exitVal = p.waitFor();
  42. System.out.println("Calor de salida:"+ exitVal);
  43.  
  44. }catch(InterruptedException e){
  45.  
  46. e.printStackTrace();
  47.  
  48.  
  49.  
  50. }
  51.  
  52. }
  53.  
  54.  
  55.  
  56. }
  57.  
  58. public class Escritura {
  59.  
  60.  
  61.  
  62. public static void main(String[] args) throws IOException {
  63.  
  64. System.out.println("Segundo programa");
  65.  
  66.  
  67. String nombre = "argumento";
  68.  
  69.  
  70. try {
  71.  
  72.  
  73. PrintWriter pw = new PrintWriter(new File("fichero.txt"));
  74.  
  75.  
  76. pw.print("nuevo fichero");
  77.  
  78.  
  79. pw.close();
  80.  
  81. System.out.println("Fichero creado correctamente");
  82.  
  83.  
  84.  
  85. } catch (FileNotFoundException ex) {
  86. Logger.getLogger(Escritura.class.getName()).log(Level.SEVERE, null, ex);
  87. }
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. }
  96.  
  97. }
Add Comment
Please, Sign In to add comment