2019.6.12Java/IO data

import java.util.*;
import java.io.*;
public class IOTest {
	
	public static void main(String[]args){
		File file = new File("d:\\data.txt");
		try{
			FileOutputStream out = new FileOutputStream(file);
			 byte str[] = "12345abcdef@#%&*软件工程".getBytes();
			 out.write(str);
			 out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		try{
			FileInputStream in = new FileInputStream(file);
			byte str[] = new byte[1024];	
			int len = in.read(str);
			System.out.println("文件中的信息是:"+new String(str,0,len));
		}catch(Exception e){
			e.printStackTrace();
		}
		File file1 = new File("d:\\data.txt");
	    //显示与文件有关的属性信息
	    System.out.println("文件或目录是否存在:" + file1.exists());
	    System.out.println("是文件吗:" + file1.isFile());
	    System.out.println("是目录吗:" + file1.isDirectory());
	    System.out.println("名称:" + file1.getName());
	    System.out.println("绝对路径:" + file1.getAbsolutePath());
	    System.out.println("文件大小:" + file1.length());

	}
}

posted @ 2019-06-12 10:58  BKKITO  阅读(182)  评论(0编辑  收藏  举报