Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.PrintWriter;
  3. import java.io.FileReader;
  4. import java.io.BufferedReader;
  5. import java.util.Scanner;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8.  
  9. public class Jurnal0 {
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args) {
  15.  
  16. File idola = new File("E:\\idola.bat");
  17. try {
  18. idola.createNewFile();
  19.  
  20.  
  21. } catch (Exception e) {
  22. System.out.println("Gagal" + e);
  23. }
  24. try {
  25. PrintWriter pw = new PrintWriter(idola);
  26. Scanner in = new Scanner(System.in);
  27.  
  28.  
  29. pw.write("Wishlist Software");
  30. pw.write("\r\n");
  31. System.out.println("Pilihan menu");
  32. System.out.println("1. Input Wishlist anda");
  33.  
  34. System.out.println("===============================");
  35. System.out.print("Masukkan jumlah barang :");
  36. int barang = in.nextInt();
  37. String[] nama = new String[barang];
  38. for (int i=1;i<=barang;i++) {
  39.  
  40. System.out.print("Tulis Barang : ");
  41. nama[i-1] = in.next();
  42. pw.write("Nama Barang :" +nama[i-1]);
  43. pw.write("\r\n");
  44. }
  45.  
  46.  
  47.  
  48. pw.close();
  49.  
  50. System.out.println("berhasil input");
  51. } catch (Exception e) {
  52. System.out.println("gagal" + e);
  53.  
  54. }
  55. System.out.println("============== DATA WISHLIST ==================");
  56.  
  57. FileReader file = null;
  58. try{
  59.  
  60. file = new FileReader("E:\\idola.bat");
  61. //Untuk membaca file
  62. BufferedReader bfr = new BufferedReader(file);
  63. String text;
  64. while ((text = bfr.readLine()) != null){
  65. System.out.println(text);
  66. }
  67. //Untuk menangani masalah program atau error
  68. }catch (FileNotFoundException e){
  69. System.out.println("Error di "+e);
  70. }catch (IOException e){
  71. System.out.println("Error di "+e);
  72. }
  73. try{
  74. //Untuk menutup file
  75. file.close();
  76. }catch (Exception e) {
  77. System.out.println("Error di "+e);
  78. }
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement