Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package learnfiles;
- import java.io.File;
- import java.util.Formatter;
- import java.util.Scanner;
- /**
- *
- * @author justahmed99
- */
- class FindFile {
- FindFile() { //Mencari file
- File file;
- file = new File(""); //Isi dengan direktori file yang ingin dicari
- if(file.exists()) {
- System.out.println(file.getName() + " is is exist");
- }
- else {
- System.out.println("The file doen't exist");
- }
- }
- }
- class ReadFile {
- ReadFile() {
- try {
- File file = new File(""); //Isi dengan file yang akan dipakai
- Scanner sc = new Scanner(file); //File yang akan dicetak
- while (sc.hasNext()) {
- System.out.print(sc.next());
- }
- sc.close();
- } catch (Exception e) {
- System.out.println("Error");
- }
- }
- }
- class CreateFile {
- CreateFile() {
- try {
- Formatter frm = new Formatter(""); //Isi dengan direktori file yang akan dibuat
- frm.format(""); //Isikan dengan tulisan yang ingin diisikan ke file
- frm.close();
- System.out.println("File is created");
- } catch(Exception e) {
- System.out.println("Error");
- }
- }
- }
- public class LearnFiles {
- public static void main(String[] args) {
- //Hapus "//" untuk mengeksekusi perintah
- //FindFile fl new FindFile();
- //ReadFile rd = new ReadFile();
- //CreateFile crt = new CreateFile();
- }
- }
Add Comment
Please, Sign In to add comment