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 }
  • 相关阅读:
    【转】VS2013编译libjpeg库
    玩转百度地图(二)之画圆,高德地图、搜搜地图、搜狗地图等稍微修改即可
    JAVA自动生成正则表达式工具类
    S2SH商用后台权限系统第三讲
    自定义表单验证指令
    关于input/textarea提交内容空格回车转换问题,以及ng-model去除空格问题
    angular ui-router 缓存问题
    ionic 发送请求返回一直都是404
    ionic中获取坐标方法
    ionic的scroll的使用出现的问题
  • 原文地址:https://www.cnblogs.com/the-wang/p/6753132.html
Copyright © 2011-2022 走看看