zoukankan      html  css  js  c++  java
  • FileTest

    CreatFile

     1 package filetest;
     2 import java.io.*;
     3 import java.util.*;
     4 public class CreatFile {
     5 
     6     public CreatFile(){
     7             File file = new File("E:\eclipse\filetest"+File.separator+"hello.txt");
     8         try {
     9             file.createNewFile();
    10         } catch (IOException e) {
    11             // TODO Auto-generated catch block
    12             e.printStackTrace();
    13             }
    14        Scanner fin;
    15     try {
    16         fin = new Scanner(file);
    17         while(fin.hasNext()){
    18            String s = fin.next();
    19            System.out.println(s);
    20            
    21        }
    22     } catch (FileNotFoundException e) {
    23         // TODO Auto-generated catch block
    24         e.printStackTrace();
    25     }
    26        
    27     }
    28     public static void main(String[] args) throws IOException {
    29     //    CreatFile f = new CreatFile();
    30         File file = new File("E:\eclipse\filetest"+File.separator+"hello.txt");
    31         file.createNewFile();
    32         Scanner fin = new Scanner(file);
    33         while(fin.hasNext()){
    34            String s = fin.next();
    35            System.out.println(s);
    36            
    37        }
    38 
    39     }
    40 
    41 }

    InputStream

     1 package filetest;
     2 
     3 import java.io.*;
     4 
     5 
     6 public class InPutStream {
     7 
     8     public static void main(String[] args) throws IOException {
     9      int len;
    10      byte[] buffer = new byte[100];
    11      File file = new File("E:\eclipse\filetest"+File.separator+"hello_1.txt");
    12      FileInputStream fin = new FileInputStream(file);
    13      while((len=fin.read(buffer))>0){
    14         String s = new String(buffer,0,len);
    15         System.out.println(s);
    16          
    17      }
    18     }
    19 
    20 }

    OutputStream

     1 package filetest;
     2 import java.io.*;
     3 public class OutPutStream {
     4 
     5     public static void main(String[] args) throws IOException {
     6     byte[] buffer = "get string!".getBytes();
     7     String filename = "E:\eclipse\filetest"+File.separator+"hello_1.txt";
     8     FileOutputStream fout = new FileOutputStream(filename);
     9     
    10     fout.write(buffer);
    11 
    12     //System.out.println();
    13     }
    14 
    15 }

    ReaderWriter

     1 package filetest;
     2 import java.io.*;
     3 
     4 public class ReaderWriter {
     5 
     6     public static void main(String[] args) throws IOException {
     7         //读入字符数据
     8     char s[] = new char [10];
     9     File file = new File("E:\eclipse\filetest"+File.separator+"hello.txt");
    10     FileReader fin = new FileReader(file);
    11     fin.read(s);
    12     System.out.println(s);
    13     fin.close();
    14         //输出字符数据
    15     char []c ={'j','a','v','a'};
    16    //File file = new File("E:\eclipse\filetest"+File.separator+"hello.txt");
    17     FileWriter fout = new FileWriter(file);
    18     fout.write(c);
    19     System.out.println(c);
    20     fout.close();
    21     }
    22 
    23 }
  • 相关阅读:
    部分页面开启宽屏模式
    门户diy实现翻页功能的方法
    git命令详解,从入门到装逼
    array方法常用记载
    vue 生命周期的理解(created && mouted的区别)
    微信小程序传值的几种方式
    data-*
    本地存储和会话存储以及cookie的处理
    vue的安装和项目构建
    进击的UI----------动画
  • 原文地址:https://www.cnblogs.com/the-wang/p/6753132.html
Copyright © 2011-2022 走看看