Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.PrintWriter;
- import java.io.FileReader;
- import java.io.BufferedReader;
- import java.util.Scanner;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- public class Jurnal0 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- File idola = new File("E:\\idola.bat");
- try {
- idola.createNewFile();
- } catch (Exception e) {
- System.out.println("Gagal" + e);
- }
- try {
- PrintWriter pw = new PrintWriter(idola);
- Scanner in = new Scanner(System.in);
- pw.write("Wishlist Software");
- pw.write("\r\n");
- System.out.println("Pilihan menu");
- System.out.println("1. Input Wishlist anda");
- System.out.println("===============================");
- System.out.print("Masukkan jumlah barang :");
- int barang = in.nextInt();
- String[] nama = new String[barang];
- for (int i=1;i<=barang;i++) {
- System.out.print("Tulis Barang : ");
- nama[i-1] = in.next();
- pw.write("Nama Barang :" +nama[i-1]);
- pw.write("\r\n");
- }
- pw.close();
- System.out.println("berhasil input");
- } catch (Exception e) {
- System.out.println("gagal" + e);
- }
- System.out.println("============== DATA WISHLIST ==================");
- FileReader file = null;
- try{
- file = new FileReader("E:\\idola.bat");
- //Untuk membaca file
- BufferedReader bfr = new BufferedReader(file);
- String text;
- while ((text = bfr.readLine()) != null){
- System.out.println(text);
- }
- //Untuk menangani masalah program atau error
- }catch (FileNotFoundException e){
- System.out.println("Error di "+e);
- }catch (IOException e){
- System.out.println("Error di "+e);
- }
- try{
- //Untuk menutup file
- file.close();
- }catch (Exception e) {
- System.out.println("Error di "+e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement