Look at the properties of the file:
System.out.println (F.getname ());//File name
System.out.println (F.length ());//byte size
System.out.println (F.getabsolutepath ());//absolute path
System.out.println (F.canread ());//Whether the file is readable
System.out.println (F.canwrite ());//whether writable
System.out.println (F.isdirectory ()); Whether it is a folder
File Related knowledge:
File F = new file ("D:/java/aaa.txt"); //Locate the target file
To create a file read object
Input byte stream for file
FileInputStream fis = new FileInputStream (f);
Read file
Byte[] B = new byte[(int) f.length ()];
If you read the last-1 means no more reading
General wording
int i = 0;
while ((i = Fis.read ())!=-1) {
System.out.println ((char) i);
//}
Advanced notation
Byte[] B = new byte[(int) f.length ()];
Reads all the contents of the file into a byte array.
Fis.read (b, 0, b.length);
for (int i = 0; i < b.length;i++) {
System.out.println ((char) b[i]);
}
Write
Output byte stream for file
FileOutputStream fos = new FileOutputStream ("C:/bbb.txt");
Input
Fos.write (b);
Fis.close ();
Empty the memory
Fos.flush ();
Fos.close ();
Wrap a byte stream into a character stream
CharSet American Character Set iso-8859-1
Give a character set of encoding format Chinese Utf-8
InputStreamReader ISR = new InputStreamReader (FIS, "utf-8");
Implementing object-Oriented Programming with Java (10)