Filenames and Pathnames

俺的java基础不太好,所以每天都要花时间来熟悉java;
将每天学的东西贴上来:
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
	    }

你可能感兴趣的:(java)