Miletone

Rp0 / Rp1.000.000

Monday, January 11, 2021

[JAVA] HOW TO MAKE FILE (.txt) with filled.

 import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args) throws IOException{

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

//attach keyboard to DataInputStream 

        DataInputStream dis=new DataInputStream(System.in); 

  

        // attach file to FileOutputStream 

        FileOutputStream fout=new FileOutputStream("file.txt"); 

  

        //attach FileOutputStream to BufferedOutputStream 

        BufferedOutputStream bout=new BufferedOutputStream(fout,1024); 

        System.out.println("Enter text (@ at the end):"); 

        char ch; 

  

        //read characters from dis into ch. Then write them into bout. 

        //repeat this as long as the read character is not @ 

        while((ch=(char)dis.read())!='@') 

        { 

            bout.write(ch); 

        } 

        //close the file 

        bout.close(); 

    }  

    }


[JAVA] MEMBUAT FILE TEXT (.txt) dengan isinya.

[JAVA] HOW TO MAKE FILE (UNCATHEGORY).

  import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

try  

{  

Scanner sc=new Scanner(System.in);         //object of Scanner class  

System.out.print("Enter the file name: ");  

String name=sc.nextLine();              //variable name to store the file name  

FileOutputStream fos=new FileOutputStream(name, true);  // true for append mode  

System.out.print("Enter file content: ");         

String str=sc.nextLine()+"\n";      //str stores the string which we have entered  

byte[] b= str.getBytes();       //converts string into bytes  

fos.write(b);           //writes bytes into file  

fos.close();            //close the file  

System.out.println("file saved.");  

}  

catch(Exception e)  

{  

e.printStackTrace();          

}     System.out.println("Data yang anda input, selesai");

    }

}


[JAVA] MEMBUAT FILE (BELUM TERKATEGORI).

 import java.io.*;

import java.util.Scanner;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

try  

{  

Scanner sc=new Scanner(System.in);         //object of Scanner class  

System.out.print("Enter the file name: ");  

String name=sc.nextLine();              //variable name to store the file name  

FileOutputStream fos=new FileOutputStream(name, true);  // true for append mode  

System.out.print("Enter file content: ");         

String str=sc.nextLine()+"\n";      //str stores the string which we have entered  

byte[] b= str.getBytes();       //converts string into bytes  

fos.write(b);           //writes bytes into file  

fos.close();            //close the file  

System.out.println("file saved.");  

}  

catch(Exception e)  

{  

e.printStackTrace();          

}     System.out.println("Data yang anda input, selesai");

    }

}


[JAVA] MAKE A FOLDER.

 import java.io.*;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

       String dirname = "D:\\test";

      File d = new File(dirname);

      

      // Create directory now.

      d.mkdirs();

        System.out.println("Data yang anda input, selesai");

    }

}

[JAVA] MEMBUAT FOLDER.

 import java.io.*;

/**

 *

 * @author ANDI

 */

public class InputFile {

    public static void main (String [] args){

        /*File f = new File("D:\\stream.doc");

        FileOutputStream out;

        PrintStream p;

        try {

            out = new FileOutputStream("D:\\stream.doc");

            p = new PrintStream(out);

            p.println("Ini String yang di tulis ke file");

            p.println("bla bla bla");

            p.close();

        } catch (Exception e) {

            System.err.println("Error Writting to file");

        }*/

       String dirname = "D:\\test";

      File d = new File(dirname);

      

      // Create directory now.

      d.mkdirs();

        System.out.println("Data yang anda input, selesai");

    }

}

[JAVA] How to read data stream from the any file.

 import java.io.*;


/**

 *

 * @author ANDI

 */

public class JavaStream {


    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic here

        //baca stream dari text

        try {

            FileInputStream fstream = new FileInputStream("D:\\File Netbeans\\JavaStream\\src\\stream\\test.txt  ");

            DataInputStream dataInput = new DataInputStream(fstream);

            while(dataInput.available()!=0)

            {

                String data = dataInput.readLine();

                System.out.println(data);

            }

            dataInput.close();

        }

        catch (Exception e) {

            System.err.println("File Input Error");

            }

        }

        

    }