Java 初学者-javaIO5

今天学习了什么?

今天继续学习了javaIO的有关操作。

FileInputStream

import java.io.*;
public class FileInputStream06 {

            public static void main(String[] args) {
                // TODO Auto-generated method stub
                       FileInputStream fis=null;
                       
                       //文件内容1decdef
                       try {
                           fis=new FileInputStream("E:\\java数据文件\\a.TXT");
                           //利用byte数组读数据
                    
                           int k=fis.available();//获取文件所有的字节数
                           byte[] bytes=new byte[k];
                          
                        
                          
                            //int   read=fis.read(bytes);//用来读取字节数据
                           fis.skip(3);//跳过三个字节
                           int   read=fis.read(bytes);
                           System.out.print(new String(bytes));
                           
                        
                         
                        
                    
                       }catch(FileNotFoundException e) {
                           e.printStackTrace();
                       }catch(IOException e) {
                           e.printStackTrace();
                       }finally {
                           
                           if(fis!=null) {
                               try {
                                   fis.close();
                               }catch(IOException e) {
                                   e.printStackTrace();
                               }
                           }
                       }
            }
View Code

 

FileOutputStream

View Code

 明天学习什么?

明天继续学习IO操作。

posted @ 2020-08-07 21:30  好吗,好  阅读(89)  评论(0)    收藏  举报