Membuat Folder dan File Menggunakan Program Java


Membuat Folder

import java.io.File;

/**
 *
 * @author windu purnomo
 */
public class CreateDirectory{

    public static void main(String[] args) {

        try{
            boolean success = (new File("windu/hapshoh")).mkdirs();
            if(success){
                System.out.println("multi direktori berhasil dibuat");
            }else{
                System.out.println("multi direktori gagal dibuat");
            }

            success = (new File("windupurnomo")).mkdir();
            if(success){
                System.out.println("direktori tunggal berhasil dibuat");
            }else{
                System.out.println("direktori tunggal gagal dibuat");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}


Membuat File

import java.io.BufferedWriter;
import java.io.FileWriter;

/**
 *
 * @author windu purnomo
 */
public class BatchCreator {

    public static void main(String[] args) {
        String contentFile = "Tulisan ini akan ada dalam file";
        String contentHTML = "<html>\n" +
                "<head>\n" +
                "\t<title>Windu Purnomo</title>\n" +
                "<body>\n" +
                "Ini adalah isi dari File HTML yang dibuat oleh program java...." +
                "</body>\n" +
                "</head>\n" +
                "</html>";
        try{
            BufferedWriter writer = new BufferedWriter(new FileWriter("windu.txt"));
            writer.write(contentFile);
            writer.close();

            BufferedWriter penulis = new BufferedWriter(new FileWriter("windu.html"));
            penulis.write(contentHTML);
            penulis.close();

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

About windupurnomo

I'm interested in programming. I am active with several programming such as Java, C #, C, JavaScript, HTML. I'm also develop desktop application (Java Swing), Mobile Application (Android), and Web programming (ASP MVC).
This entry was posted in Java and tagged , , , , , . Bookmark the permalink.

4 Responses to Membuat Folder dan File Menggunakan Program Java

  1. sandy says:

    kurang jelas tulisannya,,,

    gedean dikit donk,,,

  2. Nowo says:

    kenapa koq saya ndak bisa pake yang BatchCreator
    bukannya panggilnya
    new BatchCreator();
    trus filenya dibuat dimana?

    • windupurnomo says:

      compile: javac BatchCreator.java
      Run: java BatchCreator

      File akan digenerate pada tempat sesuai dengan lokasi BatchCreator.java

  3. panjul says:

    trimakasih trimakasih scriptnya..anu saya g begitu bisa java soalnya lo ad tgs jd browsing aj

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s