zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    如何把项目上传到github
    springBoot整合Mybatis为什么可以省略mybatis-config.xml
    【Mybatis源码解析】-mybatis-spring原理解析
    没有名字 [整除分块优化dp]
    替身使者 [区间dp]
    P3158 [CQOI2011]放棋子 [动态规划]
    博士之时 [分类讨论, 计数]
    曾有两次 [最短路树]
    序列 [线段树]
    城镇 [树的直径, 启发式合并]
  • 原文地址:https://www.cnblogs.com/chenyanlong/p/7846672.html
Copyright © 2011-2022 走看看