Tutorial Basic - How To Create File Or Folder Information On Java Programming

in #utopian-io6 years ago (edited)

What Will I Learn?

  • You will learn about java programming language
  • You will learn how to view the contents of the file in comant pront
  • You will learn input and outpur streams
  • You will learn the types of frequently used streams

Requirements

  • You need a strong intention in starting anything
  • You need basic java programming
  • You need basic Input and Output Streams

Difficulty

  • Basic

Tutorial Contents

On this occasion I will give a tutorial to you all about how to view an information in a folder or file using java programming language that will be executed on commant pront and here will also discuss how to create streams for program that will be produced, and if you want to create the program then you should follow the steps below:

  • In the first step, like most programming languages that it must create a form of the previous file in the text editor for the placement of the syntax to be written and on occasion this time the author create a file with the name ShowDirectory.java

  • The second step is to fill in the syntax that the author will give, and each given syntax will be described in detail so that readers can easily understand each syntax that will be given, and the syntax is contained below:

the syntax below is the beginning of the initial declaration to start the program and its class named ShowDirectory should be the same as the title of the saved file and public static void main (String args []) main declaration in java language and this is mandatory in writing syntax java programming

import java.io. *;
public class ShowDirectory {
public static void main (String args []) {

The syntax below serves as a data type in java programming language and syntax File fn = new File (fileName); useful as destination address for declaration and System.out.println ("Name:" + fn. getName ()); is useful for displaying the line item because there is a line word and then the whole is the same.

String fileName = args[0];
File fn = new File(fileName);
System.out.println("Name: " + fn.getName());
if (!fn.exists()) {
System.out.println(fileName + " does not exists.");

In the syntax below is useful to display the results of text Creating Utopian Directory In Process, Please Be Patient and then for the creation of the folder using syntax fn.mkdir (); next appearance results for text Deleting Utopian Directory In Process, Please Be Patient .

System.out.println("Creating Utopian Directory In Process, Please Be Patient...");
fileName = "Utopian";
fn = new File(fileName);
fn.mkdir();
System.out.println(fileName + (fn.exists()? "exists" : " does not exist."));
System.out.println("Deleting Utopian Directory In Process, Please Be Patient...");
fn.delete();
System.out.println(fileName + (fn.exists()? "exists" : " does not exist."));
return;
}

In the command below is useful to display the results of the command System.out.println (fileName + "is a" + (fn.isFile ()? "file.": "directory.");) and then the syntax for the condition of the directory that we make for the next only done looping for syntax above and penampilhan result of text line

System.out.println(fileName + " is a " + (fn.isFile()? "file." :"directory."));
if (fn.isDirectory()) {
String content[] = fn.list();
System.out.println("The content of this  Utopian directory:");
for (int i = 0; i < content.length; i++) {
System.out.println(content[i]);
}

The syntax this time serves as if the user wants to read it will get a notification that the file is not readable

}
if (!fn.canRead()) {
System.out.println(fileName + "Utopian directory can not be read.");
return;
}

in this syntax serves as the result viewer from the long filename folder bytesnya can be modified and as the viewer results from the text Utopian directory is not writable

System.out.println(fileName + " is " + fn.length() + " bytes long.");
System.out.println(fileName + " is " + fn.lastModified() + " bytes long.");
if (!fn.canWrite()) {
System.out.println(fileName + "Utopian directory is not writable.");
}
}
}
  • And after following the steps above then you have to compile your program on commant pront to get the result, as shown below:

111111.JPG

All the syntax programs are listed below:

import java.io.*;
public class ShowDirectory {
public static void main(String args[]) {
    
    String fileName = args[0];
    File fn = new File(fileName);
    System.out.println("Name: " + fn.getName());
    if (!fn.exists()) {
    System.out.println(fileName + " does not exists.");

        System.out.println("Creating Utopian Directory In Process, Please Be Patient...");
        fileName = "Utopian";
        fn = new File(fileName);
        fn.mkdir();
        System.out.println(fileName + (fn.exists()? "exists" : " does not exist."));
        System.out.println("Deleting Utopian Directory In Process, Please Be Patient...");
        fn.delete();
        System.out.println(fileName + (fn.exists()? "exists" : " does not exist."));
        return;
        }
        
            System.out.println(fileName + " is a " + (fn.isFile()? "file." :"directory."));
            if (fn.isDirectory()) {
            String content[] = fn.list();
            System.out.println("The content of this  Utopian directory:");
            for (int i = 0; i < content.length; i++) {
            System.out.println(content[i]);
            }
            
                }
                if (!fn.canRead()) {
                System.out.println(fileName + "Utopian directory can not be read.");
                return;
                }
                
                    System.out.println(fileName + " is " + fn.length() + " bytes long.");
                    System.out.println(fileName + " is " + fn.lastModified() + " bytes long.");
                    if (!fn.canWrite()) {
                    System.out.println(fileName + "Utopian directory is not writable.");
                    }
    }
}

Hopefully this tutorial can be useful



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

@brainalien, Upvote is the only thing I can support you.

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • This contribution is considered, simple programming basic are no longer accepted as utopian contribution

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.033
BTC 64106.00
ETH 3129.71
USDT 1.00
SBD 4.16