Home > Java > Menulis Data File .txt

Menulis Data File .txt

September 10, 2012 Leave a comment Go to comments

Berikut ini contoh code Java untuk menulis file .txt

package io_writefile;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileWriter;

/**
 *
 * @author Taeyeon
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BufferedWriter writer = null;
        try
        {   String textString = "Kukuh Utama";
           writer = new BufferedWriter(new FileWriter("C:\\Output.txt"));
           writer.write(textString);
        
        }
        catch(FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            try{
                if(writer != null)
                    writer.close();
               }
            catch(IOException ex)
            {
                ex.printStackTrace();
            }
        }
    }

}

Nama file : Output.txt
Lokasi File :  C:\

Semoga bermanfaat

Referensi : Dari berbagai sumber

  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: