码迷,mamicode.com
首页 > 其他好文 > 详细

醉了,下课了

时间:2017-11-17 00:08:52      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:close   author   rac   com   leo   generated   span   try   rate   

技术分享
 1 package com.mon11.day16.file;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 /** 
 7 * 类说明 :
 8 * @author 作者 :chenyanlong
 9 * @version 创建时间:2017年11月16日 
10 */
11 public class Fileoper1 {
12 
13     public static void main(String[] args) {
14         
15         Fileoper1 fm=new Fileoper1();
16         File file=null;
17         file =new File("C:\\Users\\Administrator\\Desktop\\3.txt");
18         try {
19             file.createNewFile();
20         } catch (IOException e) {
21             // TODO Auto-generated catch block
22             e.printStackTrace();
23         }
24         
25     }
26     
27     /**
28      * 创建类的方法
29      * @param file文件对象
30      */
31     public void create(File file){
32         if(!file.exists()){
33             try {
34                 file.createNewFile();
35                 System.out.println("文件已经创建");
36             } catch (IOException e) {
37                 e.printStackTrace();
38             }
39         }
40     }
41     
42     /**
43      * 显示文件信息
44      * @param file文件对象
45      */
46     public void showFileInfo(File file){
47         if(file.exists()){//判断文件是否存在
48             if(file.isFile()){//如果是文件
49                 System.out.println("名称:"+file.getName());
50                 System.out.println("相对路径:"+file.getPath());
51                 System.out.println("绝对路径:"+file.getAbsolutePath());
52                 System.out.println("文件大小:"+file.length()+"字节");
53             }
54             
55             if(file.isDirectory()){
56                 System.out.println("此文件是目录");
57             }
58             
59         }else{
60             System.out.println("文件不存在");
61         }
62     }
63     
64     /**
65      * 删除文件
66      * @param file文件对象
67      */
68     public void delete(File file){
69         if(file.exists()){
70             file.delete();
71             System.out.println("文件已删除");
72         }
73     }
74 
75 }
View Code

 

醉了,下课了

标签:close   author   rac   com   leo   generated   span   try   rate   

原文地址:http://www.cnblogs.com/chenyanlong/p/7846672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!