Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.BufferedWriter;
  10. import java.io.FileWriter;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13.  
  14. /**
  15. *
  16. * @author alex
  17. */
  18. public class InputStreamReaderjava {
  19. public static void main(String[] args) throws IOException {
  20.  
  21. InputStreamReader in = new InputStreamReader(System.in);
  22. BufferedReader br = new BufferedReader(in);
  23.  
  24. String texto, texto2;
  25.  
  26. System.out.println("Introduce una nombre para crear...");
  27. texto = br.readLine();//lee buffer
  28. System.out.println("fichero " + texto + " creado");
  29.  
  30.  
  31. System.out.println("Introduce texto a escribir...");
  32. texto2 = br.readLine();
  33. escribir(texto,texto2);
  34.  
  35. in.close();
  36.  
  37.  
  38. }
  39.  
  40. public static void lecturaLineas(BufferedReader br) throws IOException {
  41. String linea = br.readLine();
  42. while (linea != null) {
  43. System.out.println(linea);
  44. linea = br.readLine();
  45. }
  46. System.out.println(linea);
  47. }
  48.  
  49. public static void escribir(String texto, String texto2) throws IOException {
  50.  
  51. try (BufferedWriter fichero = new BufferedWriter(new FileWriter(texto, true))) {
  52. fichero.write(texto2);
  53. fichero.newLine();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement