• Document


     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
  • 相关阅读:
    最好的我们
    外滩
    外滩
    Java EE (5) -- Java EE 6 JavaServer Faces Developer Certified Expert(1z0-896)
    列表list(序列)、元组tuple(序列)
    P1165 日志分析 洛谷
    T1365 浴火银河星际跳跃 codevs
    T1503 愚蠢的宠物 codevs
    P2820 局域网 洛谷
    T1992 聚会 codevs
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/7846672.html
Copyright © 2020-2023  润新知