File class (package java.io.*) is an abstract representation of file and directory pathnames. Each operating systems use system-dependent pathname strings to name files and directories(Windows use like this "C:\\DIR_NAME\\File_NAME" and Linux uses "/usr/local/file_name"). In order to deal each fie in system independent manner , this class presents an abstract, system-independent view of hierarchical pathnames.
Below are sample codes associated with various File operations.Refer each link for detailed explanation and sample Java program for the same.
How Java makes file handling and associated operations platform independent?
In Java "File class" maintains FileSystem object representing the platform's local file system and also maintains various static fields like separator,pathSeparator which got initialized automatically when File is loaded in JVM. FileSystem object in File Class:- static private FileSystem fs = FileSystem.getFileSystem();
Separator character on UNIX systems is '/' and on Microsoft Windows systems it is '\\'
public static final char separatorChar = fs.getSeparator();
public static final String separator = "" + separatorChar; // String separator for convenience
Path separator character on UNIX systems is ':' and on Microsoft Windows systems it is ';'
public static final char pathSeparatorChar = fs.getPathSeparator();
public static final String pathSeparator = "" + pathSeparatorChar; // String patseparator for convenience
Java ships with very rich I/O classes to support the input and output through bytes stream and file system.In Java File I/O posts we will discuss various operations associated with File class and visit code lines for the same. Before moving ahead with individual examples(creating file, read ,write operations, etc) and understanding various I/O classes available in Java, it needs special mention: File object is created for handling both file and directory and all operation is performed on this File object.When we say File object, we refers to both file(.txt, .xml) or directory.File Class provides API for distinguishing file and directory, however internally both are same(File Object)In Java "File class" maintains FileSystem object representing the platform's local file system and also maintains various static fields like separator,pathSeparator which got initialized automatically when File is loaded in JVM. FileSystem object in File Class:- static private FileSystem fs = FileSystem.getFileSystem();
Separator character on UNIX systems is '/' and on Microsoft Windows systems it is '\\'
public static final char separatorChar = fs.getSeparator();
public static final String separator = "" + separatorChar; // String separator for convenience
Path separator character on UNIX systems is ':' and on Microsoft Windows systems it is ';'
public static final char pathSeparatorChar = fs.getPathSeparator();
public static final String pathSeparator = "" + pathSeparatorChar; // String patseparator for convenience
Below are sample codes associated with various File operations.Refer each link for detailed explanation and sample Java program for the same.
- Create, Rename, Delete a file in Java
- Get Meta data of file
- Read and write operation in Java
- Display all files/directories (File Object)
- Filter files with specific extension (.txt, .doc)
- Get and Set File permission
- Create temporary file and automatic clean-up
Aivivu chuyên vé máy bay, tham khảo
ReplyDeletekinh nghiệm mua vé máy bay đi Mỹ giá rẻ
chuyến bay hồi hương từ mỹ về việt nam
vé máy bay nhật việt
đặt vé máy bay từ đức về việt nam
giá vé máy bay từ Toronto đến việt nam
đặt vé máy bay từ hàn quốc về việt nam
토토365프로
ReplyDelete토토사이트
Fine way of describing, and nice article to take facts about my presentation topic,
I totally agree with what you have said!!
ReplyDeleteThe information provided by you is helpful for me.
ReplyDeleteWish to see much more like this.
ReplyDelete