Java学习之IO之File类一

File的操作

 1 package com.gh.file;
 2 import java.io.File;
 3 import java.io.IOException;
 4 /**
 5  * File操作
 6  * @author ganhang
 7  *
 8  */
 9 public class FileDemo {
10     public static void main(String[] args) {
11         //File.separator表示 '/'
12         File file =new File("1.txt");
13         try {
14             file.createNewFile();
15         } catch (IOException e) {
16             e.printStackTrace();
17         }
18         System.out.println(file.getParent());
19         File file2 =new File("D:\");
20         String [] filenames=file2.list();
21         for(String s:filenames){//输出d盘下的所有文件名
22             System.out.println(s);
23         }
24     }
25 }
原文地址:https://www.cnblogs.com/ganhang-acm/p/5154240.html