呆呆的io流输入输出的一些基础

          关于io流的File类,下面来码一些基础属性:

             文件的属性:

1 /*
2      public  String    getName()       获取文件的名字
3      public  boolean canRead()      判断文件是否可以读的
4      public  boolean canWrite()     判断文件是否是可以被写入
5      public  boolean exists()         判断文件是否存在
6      public  long length()             获取文件的长度
7      public   String   getAbsolutePath() 获取文件的绝的路径
8 */

举列子:

 1 package DEMO;
 2 
 3 /*创建一个文件,判断他的
 4  * (1)可读性以及
 5  * (2)可输入性,
 6  * (3)绝对路径,
 7  * (4)是否创建成功
 8  * */
 9 import java.io.File;
10 import java.io.IOException;
11 
12 public class test 
13 {
14    private static void out(String  pre,String name,String ude)
15    {
16       System.out.println(pre+name+ude);
17    }
18    
19    private static void out(String pre,String name,boolean judge)
20    {
21       System.out.println(pre+name+judge);
22    }
23    private static void out(String pre ,String name,int len)
24    {
25        System.out.println(pre+name+len);
26    }
27   public static void main(String args [])
28   {
29     File myfile= new File("e:\demo","test.java");
30        out(myfile.getName(),"的可读性:",myfile.canRead());
31        out(myfile.getName(),"的可写入性:",myfile.canWrite());
32        out(myfile.getName(),"的绝对路径: ",myfile.getAbsolutePath());
33      out(myfile.getName(),"的长度: ",(int)myfile.length());     
34      File mt= new File("test.txt");   //在当前的目录下创建文件。
35      if(!mt.exists())
36      {
37          try
38          {
39             mt.createNewFile();
40             System.out.println("创建成功");     
41          }
42          catch(IOException exp){
43             System.out.println("hehe"); 
44          }
45      }
46   }
47 }

      1234 5      6       7        8        9      0                                                        7

原文地址:https://www.cnblogs.com/gongxijun/p/3873545.html