简体   繁体   中英

How to Get reference of Opened file in Java?

I want to build a method that opens an existing file and returns a reference to said file (Like a file handle) as an object. If I succeed in opening this file, then the fields of the file handle should be initialized with the information about the opened file, like for example the number of blocks stored in that file. Any Idea how to go about this? Any suggestions would be appreciated.

File fileReference = new File("/path/to/your/file");
if (fileReference.isFile()) {
  long length = fileReference.length();
  // etc.
}

See more available methods on the File class: https://docs.oracle.com/javase/7/docs/api/java/io/File.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM