---
title: "How to determining File Length in java"  
description: "How to determining File Length in java"  
author: "Jonas Stuart"  
published: 2016-07-06  
updated: 2016-07-06  
canonical: https://www.mindstick.com/forum/34150/how-to-determining-file-length-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to determining File Length in java

Hi Guys \
I am [beginner](https://www.mindstick.com/forum/23159/need-beginner-project-ideas) in java [programming](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) .I want to know that how to write [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) for determining [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) length.\
Thanks

## Replies

### Reply by Manoj Bhatt

**The program for determining the length of a file is given in here:**

```
 public
class FileLength {                     public static void main(String[] args) {                             int count = 0;                             InputStream streamReader = null;                             if (args.length < 1) {                                      System.out.println("Usage:java FileLength <filename>");                                      System.exit(0);                             }                             try {                                      streamReader= new FileInputStream(args[0]);                                      while(streamReader.read() != -1) {                                                count++;                                      }                                      System.out.println(args[0]+ " length = " + count);                                      streamReader.close();                             } catch (FileNotFoundException fe) {                                      System.out.println("File" + args[0] + " was not found");                                      System.exit(0);                             } catch(IOException ie) {                                      System.out.println("Error reading file");                             } finally {                                      try {                                                streamReader.close();                                      } catch (Exception e) {                                                e.printStackTrace();                                      }                             }                     }}
```


---

Original Source: https://www.mindstick.com/forum/34150/how-to-determining-file-length-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
