将每天学的东西贴上来:
1. Constructing a Filename Path
2.Creating a File
3.Getting the Size of a File
4.Renaming a File or Directory
1. Constructing a Filename Path
- String path = File.separator + "a" + File.separator + "b";
- System.out.println("-----------> "+path);
2.Creating a File
- File file = new File("filename.txt");
- // Create file if it does not exist
- boolean success = file.createNewFile();
3.Getting the Size of a File
- File file = new File("filename.txt");
- // Get the number of bytes in the file
- long length = file.length();
- System.out.println("length------------->"+length);
4.Renaming a File or Directory
- // File (or directory) with old name
- File file = new File("filename.txt");
- // File (or directory) with new name
- File file2 = new File("file.txt");
- // Rename file (or directory)
- boolean success = file.renameTo(file2);
- if (!success) {
- // File was not successfully renamed
- }
浙公网安备 33010602011771号