javaIO流之File类
来源:互联网 发布:知网阅读器mac 编辑:程序博客网 时间:2024/05/01 04:13
在java中File类主要是表示文件和目录,只能创建文件,而不能访问文件;
File的构造函数如下:
File(File file,String str)File(String dircetory)File(String directory,String filename)file是一个File对象,directory是文件所在目录的路径名,
用下列的例子来说明几个常用的方法
package com.test;import java.io.File;import java.io.IOException;public class FILE {public static void main(String[] args)throws IOException {File file = new File("D:\\learning\\FILE");//Create File objectif(!file.exists()){//To determine whether the directory existsfile.mkdir();//Create directory}System.out.println(file.isDirectory());//To see if it is a directorySystem.out.println(file.isFile());//To see if it is a fileFile file1 = new File("D:\\learning\\FILE\\file.txt");//Create File objectif(!file1.exists()){file1.createNewFile();//Create file}System.out.println(file.getAbsolutePath());//Absolute path string for the print directorySystem.out.println(file1.getAbsolutePath());//Absolute path string for the print fileSystem.out.println(file.getName());//View directory nameSystem.out.println(file1.getName());//View file nameSystem.out.println(file.getParent());//Get the parent directory nameSystem.out.println(file1.getParent());//Get the parent file name}}
0 0
- javaIO流之File类
- 黑马程序员之----------javaIO流File类
- JavaIO学习之File类
- javaIO学习之File
- javaIO操作之File
- javaIO file类
- 黑马程序员--javaIO 之File
- hadoop学习序曲之java基础篇--javaIO流及File类
- javaIO—File类详解
- javaIO之对象流
- javaIO流、File文件知识总结
- JavaIO 1—File类的介绍
- JavaIO —— java.io.File类
- 黑马程序员-JavaIO技术File类
- java基础知识回顾之javaIO类--File类应用:过滤器接口FilenameFilter和FileFilter
- javaIO之文件字节流
- javaIO之文件字符流
- javaIO之串联输入流
- Netbeans使用maven下载源码
- date
- 2015广东省强网杯CTF初赛题之大黑阔writeup
- Android开发之基本控件
- Android源码浅析: Message/Handler/MessageQueue/Looper
- javaIO流之File类
- ArcGIS API for JavaScript 4.0尝鲜——WebGIS前端开发大杀器
- hdu 1301 Jungle Roads【最小生成树】【MST】
- 从LayoutInflater分析XML布局解析成View的树形结构的过程
- 关于oray找回远程密码的方法
- HDU2050折线分割平面
- 数据结构-栈和队列
- SpringMVC中使用Interceptor拦截器
- cocos2dx 按钮与标签