soyan_bid

learnfile

Aug 13th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package learnfiles;
  2.  
  3. import java.io.File;
  4. import java.util.Formatter;
  5. import java.util.Scanner;
  6.  
  7.  
  8.  
  9. /**
  10.  *
  11.  * @author justahmed99
  12.  */
  13. class FindFile {
  14.     FindFile() {    //Mencari file
  15.         File file;
  16.         file = new File("");    //Isi dengan direktori file yang ingin dicari
  17.         if(file.exists()) {
  18.             System.out.println(file.getName() + " is is exist");
  19.         }
  20.         else {
  21.             System.out.println("The file doen't exist");
  22.         }
  23.     }
  24. }
  25.  
  26. class ReadFile {
  27.     ReadFile() {
  28.         try {
  29.             File file = new File("");   //Isi dengan file yang akan dipakai
  30.             Scanner sc = new Scanner(file);     //File yang akan dicetak
  31.            
  32.             while (sc.hasNext()) {
  33.                 System.out.print(sc.next());
  34.             }
  35.             sc.close();
  36.         } catch (Exception e) {
  37.             System.out.println("Error");
  38.         }
  39.     }
  40. }
  41.  
  42. class CreateFile {
  43.     CreateFile() {
  44.         try {
  45.             Formatter frm = new Formatter("");  //Isi dengan direktori file yang akan dibuat
  46.            
  47.             frm.format("");     //Isikan dengan tulisan yang ingin diisikan ke file
  48.             frm.close();
  49.            
  50.             System.out.println("File is created");
  51.         } catch(Exception e) {
  52.             System.out.println("Error");
  53.         }
  54.     }
  55. }
  56.  
  57. public class LearnFiles {
  58.  
  59.     public static void main(String[] args) {
  60.        
  61.         //Hapus "//" untuk mengeksekusi perintah
  62.        
  63.         //FindFile fl new FindFile();
  64.        
  65.         //ReadFile rd = new ReadFile();
  66.        
  67.         //CreateFile crt = new CreateFile();
  68.     }  
  69. }
Add Comment
Please, Sign In to add comment