Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Get File Size

In this Tutorial, we want to describe you a code that helps you in understanding Get File Size.

Get File Size

                         

In this Tutorial, we want to describe you a code that helps you in understanding  Get File Size. For this we have a class name" Get File Size" Inside the main method  we have -

Input Stream Reader This is used to decode a byte code and convert the byte code to a character stream.
Buffered Reader This is used to read a character stream from a file.

We declare a string variable path assigned to memory. The System.out.println is used to print the path. In the Try block readline ( ) method provides you to read the file and store in  a path variable. Incase there is an exception occurred in a try block, the catch block followed by the try block to handle the exception. Otherwise we declare file variable name dir and assigned to a memory by passing path as argument. The dir variable call a list method return you a list of files  and store in a string array file list. We display the list of array file using for loop. Now in order to evaluate the size of file we use.isfile( ),returns you the size of file present in bytes by placing in the conditional operator if clause.

GetFileSize.java


import java.io.*;

public class GetFileSize {

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

        InputStreamReader streamReader = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(streamReader);
        String path = new String();
        System.out.println("Path : ");
        try {
            path = br.readLine();
        catch (Exception e) {
            System.out.println(e);
        }

        File dir = new File(path);
        String[] fileList = dir.list();
        File file;
        for (int i = 0; i < fileList.length; i++) {
            file = new File(fileList[i]);
            if (file.isFile()) {
                System.out.println(file.getName() +
                        " : " + file.length() " Bytes");
            }
        }
    }
}

Output
Path :  .
build.xml : 3367 Bytes
manifest.mf : 85 Bytes
text.txt : 93 Bytes

Download code

                         

» View all related tutorials
Related Tags: java windows c error orm form diff io dialog icons sed format version window display icon port using log support

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.