Whether learning that language is inevitably accessible to the file system, you have to manage frequently with the file. Java is of course no exception, some netizens think that IO is very cumbersome, sometimes there is such a feeling, its practical skill, I think this thing is still very convenient. First introduce a very important class file before introducing Java IO.
After seeing this type of name, you must think it represents a file, in fact, think that it is not accurate, because the File class in Java can represent the file or represent the directory. This is illustrated in the API DOC, and the file is represented by Abstract Pathname. But think about the directory is not a special file?
File is very simple, it has four constructor: file (string parent, string child) File (uri uri) file (string pathname) where two can make us in a certain Known for a new file or directory in a specific directory, the following two we can create a file or directory through the PathName or URI. One thing to note, the file is a system-independent representative, but the PathName is related to the system, such as UNIX "/" represents the root directory, and Windows usually uses the drive letter. For example, the absolute path C: / helloworld / mingjava, if it is a relative path, it is not "/" at the beginning, the general relative path is relative to the current directory. When we create a file, you can determine if it exists through the exists () method. If there is no existence we can choose to create a file or create a directory. For example, File File = New File ("HEHE"); if (! File.exists ()) {file.mkdir ();} for (int i = 0; i <5; i ) {file listfile = new file (Nextfile "Ming" i ". TXT"); if (! listfile.exiss ()) {listfile.createNewFile ();}} If we already know a File object, I hope to create a new file under his directory, then You can use the first constructor. For example, file nextfile = new file (file, "ming // HEHE"); if (! Nextfile.exists ()) {nextfile.mkdirs ();} Note When you create multi-layer directory (). We can also list a list of files in a directory, and an array of string [] types can be obtained through the list () method, which is the file name in the directory. String [] list = nextfile.list (); for (int J = 0; j