Kodejava

Learn Java Programming by Examples


How do I get the size of a file?

Category: java.io, viewed: 4K time(s).
import java.io.File;

public class FileSize
{
    public static void main(String[] args) throws Exception
    {
        File file = new File("Housing.pdf");

        // Get the size of a file in bytes.
        long fileSize = file.length();

        // Using new features in Java to print the filesize
        System.out.printf("File size: %d%n", fileSize);
    }
}

More examples on java.io

  • How do I convert InputStream to String?
  • How do I read a text file?
  • How do I convert string into InputStream?
  • How do I use DataInputStream and DataOutputStream?
  • How do I create and write data into text file?
  • How do I get file's last modification date?
  • How do I use RandomAccessFile class?
  • How do I store objects in file?
  • How do I load properties from XML file?
  • How do I use Console class to read user input?
  • How do I store properties as XML file?
  • How do I get an exception stack trace message?
  • How do I use LineNumberReader class to read file?
  • How do I append data to a text file?
  • How can I get current working directory?
  • How do I detect non-ASCII characters in string?
  • How can I change a file attribute to writable?
  • How do I create a directories recursively?
  • How do I use Java NIO to Copy File?
  • How do I copy a file?

Example Categories

  • JSE

  • fundamental
  • java.applet
  • java.awt
  • java.awt.geom
  • java.beans
  • java.io
  • java.lang
  • java.lang.annotation
  • java.lang.management
  • java.lang.reflect
  • java.math
  • java.net
  • java.nio
  • java.security
  • java.sql
  • java.text
  • java.util
  • java.util.logging
  • java.util.regex
  • java.util.zip
  • javax.crypto
  • javax.print
  • javax.script
  • javax.swing
  • javax.tools
  • javax.xml
  • JSP / Servlet

  • javax.servlet
  • jsp.snippets
  • taglib / jstl
  • JEE

  • javax.mail
  • javax.naming
  • Hibernate

  • org.hibernate
  • MyBatis

  • org.apache.ibatis
  • Design Patterns

  • Factory Patterns
  • Apache Commons

  • commons.beanutils
  • commons.codec
  • commons.dbcp
  • commons.fileupload
  • commons.httpclient
  • commons.io
  • commons.lang
  • commons.net
  • Spring Framework

  • org.springframework
  • org.springframework.jdbc
  • Tapestry

  • Google Web Toolkit

  • GWT Panels
  • GWT Wigdets
  • GWT Listeners
  • Android

  • Others

  • com.google.gson
  • com.itextpdf
  • org.apache.poi
  • org.jasypt
  • org.jdom
  • org.joda.time

100 Top & Latest

  • Top 100 Codes
  • Latest 100 Codes
  • Browse All Codes

Network Sites

  • Learn C# by Examples
  • Programming Tutorials and Resources

Navigation

  • Home
  • Project Board
  • Free Magazines
  • Advertise
  • Links
  • RSS Feed
  • Donation
  • Follow @kodejava

The examples provided here are for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user.
Kodejava.org is a member of Kodesoft.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.