输入输出流
.createNewFile() 创建文件
//创建文件
public class t { public static void main(String[] args) { File f = new File("D:/20161229/3.txt"); try { f.createNewFile(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
.mkdir 创建文件
//创建文件夹
package hibernate; import java.io.File; import java.io.IOException; public class t { public static void main(String[] args) { File f = new File("D:/20161229/10010"); try { f.mkdir(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
//删除
public class t { public static void main(String[] args) { File f = new File("D:/20161229/10010"); try { f.delete(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
//读出D盘下 3.txt的内容!
public class t { public static void main(String[] args) { FileReader fi=null; File f = new File("D:/20161229/3.txt"); try { fi = new FileReader(f); try { int i=fi.read(); while(i!=-1){ System.out.print((char)i); i=fi.read(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(fi!=null){ try { fi.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }