一、创建文件
//1、new file(String filePath_name)通过 文件目录 创建
String filePath = 'e:\\files\\news.txt';//第一个反斜杠为转义
File file = new File(filePath);
//需要调用方法createNewFile,否则只是在内存中创建了一个File对象,并没有存储到硬盘中
file.createNewFile();
//2、new file(File parent,String fileName)通过 父目录文件+文件名 创建
File parent = new File("e:\\files\\")//方法一创建父目录
String fileName = news.txt';
File file = new File(parent,fileName);
file.createNewFile();
//3、new file(String parentPath,String filePath)通过 父目录+子路径 创建
String parentPath = 'e:\\';
String filePath = 'files\\news.txt';
File file = new File(parentPath,filePath);
file.createNewFile();
二、文件相关方法
1、获取文件信息
getName() 文件名字
getAbsolutePath() 文件绝对路径
getParent() 文件父级目录
length() 文件大小(字节)(一个汉字三个字节,一个字符一个字节&#x