栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java高级特性:File

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java高级特性:File

IO介绍

内存属于临时存储设备,断电、程序运行结束,内存释放,数据就消失。

持久化存储设备:数据可以这类设备上长久的保存。硬盘、U盘、光盘、磁带、软盘、云盘等。这些设备都可以长久的保存数据,当需要数据的时候,可以到这些设备上获取数据。

在前面学习的程序中数据最终都内存中,不是存在硬盘中,一旦程序停止运行,整个程序中的数据就没有了,

IO技术就是把程序中的数据最终输出到持久设备上。或者从设备读取已经存在的数据,最后给我们读取到程序中。

input 输入:读操作

output输出 :写操作

file类介绍

在Java中使用File 这个类来描述持久设备上的文件或者文件夹。

文件:是用来保存真实的数据的。

文件夹:管理文件和文件夹。

file常用方法
package file;

import java.io.File;

public class Demo {
	
	public static void main(String[] args) {
//		文件夹
		File file1 = new File("D:/Bandzip");
//		文件
		File file2 = new File("D:/Bandzip/hi.txt");

//		判断文件是否存在
		boolean exists = file1.exists();
//		判断是否是目录
		boolean isDirectory = file1.isDirectory();
//		返回相对路径名
		String getPath = file1.getPath();
//		返回绝对路径名
		String absolutePath = file1.getAbsolutePath();
//		返回文件或文件夹的名称
		String getName = file1.getName();
		
//		创建空文件,不创建文件夹
//		boolean createNewFile = file1.createNewFile("");
		
		System.out.println("exists:"+exists);
		System.out.println("isDirectory:"+isDirectory);
		System.out.println("getPath:"+getPath);
		System.out.println("absolutePath:"+absolutePath);
		System.out.println("getName:"+getName);
		
//		判断是否是文件
		boolean file = file2.isFile();
//		返回文件长度
		long length2 = file2.length();	
		
		System.out.println("file:"+file);
		System.out.println("length2:"+length2);	
	}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/839100.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号