zoukankan      html  css  js  c++  java
  • 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());
    
    	}
    }
    
    

  • 相关阅读:
    第二次作业——App案例分析
    第一次作业--四则运算
    一点感想
    结对编程1
    第二次作业
    第一次作业-四则运算
    我的第一篇博客
    第二次作业
    结对编程
    第二次作业 APP分析
  • 原文地址:https://www.cnblogs.com/BKKITO/p/11008303.html
Copyright © 2011-2022 走看看