How to calculate byte size of file if I declared it indirectly(BufferedReader with pathname?) (Java 6)

StackOverflow https://stackoverflow.com/questions/23249312

  •  08-07-2023
  •  | 
  •  

سؤال

Hypothetically we have this line
BufferedReader inStream = new BufferedReader(new FileReader("src.txt"));

At opening and closure of file how to calculate its size (for example with length())

inStream.legth() ? at a System.out.println()?

هل كانت مفيدة؟

المحلول

Use the length method of the File class:

 File f = new File(fileName);
 System.out.println(f.length())

Please note that you can use the f in your BufferReader object too :

 BufferedReader br = new BufferedReader(new FileReader(f));
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top