Using streams

  1 package com.ccp.Lc0813;
  2 
  3 import java.io.*;
  4 
  5 public class TextFile {
  6     public static void main(String[] args) throws IOException {
  7         File file=new File("D://text");
  8         System.out.println("——————文件——————");
  9 //        file.mkdir();
 10         File file1=new File("D://text//txt.txt");
 11         System.out.println("——————创建文件——————");
 12 //        try {
 13 //            file1.createNewFile();
 14 //        } catch (IOException e) {
 15 //            e.printStackTrace();
 16 //        }
 17         System.out.println("——————List————————");
 18         String[] list=file.list();
 19         for (String ps : list
 20         ) {
21 is              . The System OUT .println (PS);
 22 is          }
 23 is          the System. OUT .println ( " ------ ------ ListFiles " );
 24          File [] = List1 File.listFiles ();
 25          for (File file2: List1
 26          ) {
 27              System. OUT .println (file2); // file2.getAbsolutePath (); relative path (there is a train procedure) file2.getPath (); absolute path (directly to the destination Teleport) 
28          }
 29          the System. OUT .println ( " after filtration ------ -------- ");
 30         System.out.println("查找文件");
 31         FilenameFilter filenameFilter= new FileNameFile();
 32         String[] fft=file.list(filenameFilter);
 33         for (String d:fft
 34              ) {
 35             System.out.println(d);
 36         }
 37         System.out.println("——————FileFilter————————");
 38         FileFiter fileFiter=new FileFiter();
 39         File[] ft=file.listFiles(fileFiter);
 40         for (File f:ft
 41              ) {
 42             System.out.println(f);
 43         }
 44         System.out.println("———————输入流——————————");
 45         FileInputStream fi=new FileInputStream(file1);
 46         int ent=0;
 47         while ((ent=fi.read())!=-1){
 48             System.out.print (( char ) ENT);
 49          }
 50          fi.close ();
 51 is          . the System OUT .println ();
 52 is          . the System OUT .println ( " ------ ------- output stream --- " );
 53 is          a FileOutputStream FO = new new a FileOutputStream (file1, to true ); // the append additional information 
54 is          String STR = " people are iron rice is steel " ;
 55          fo.write (str.getBytes ());
 56 is          FO .flush (); // refresh 
57         fo.close();
 58         System.out.println("-——————字节流——————————");
 59         FileReader fr=new FileReader(file1);
 60         char[] rr=new char[1024];
 61         int enr=0;
 62         while ((enr=fr.read(rr))!=-1){
 63             System.out.println(new String(rr,0,enr));
 64         }
 65         fr.close();
 66         System.out.println("——————字符流——————————");
 67         FileWriter fw=new FileWriter(file1,true);
 68         fw.write("kkkooo");
 69         fw.flush();
 70         fw.close();
 71         System.out.println("————————传文件————————");
 72         FileInputStream f1=new FileInputStream(file1);
 73         FileOutputStream f2=newA FileOutputStream (File, to true ); // the append additional information 
74          int ENT1 = 0 ;
 75          the while ((ENT1 = f1.read ()) = -! . 1 ) {
 76              f2.write (ENT1);
 77          }
 78          f2.flush (); // refresh 
79          f2.close ();
 80          f1.close ();
 81  
82          // video from one position to another position, the transmission of a byte stream
 83  
84          // source 
85          file fileold = new new File ( " D: \\ text \\ \\ txt77.txt ttf" );
 86          // object file 
87          File FileNew = new new File ( " D: \\ \\ txt.txt text " );
 88          // requires two files associated conduit 
89          the FileInputStream FIS = new new the FileInputStream (fileold);
 90          fos = a FileOutputStream new new a FileOutputStream (FileNew);
 91 is          // transmission process, is read out in fis fos 
92          int len = 0 ;
 93          the while (! (len = fis.read ()) = - . 1 ) {
 94              fos. Write (len);
 95             The System. OUT .print (len + "  " );
 96          }
 97          // Close Channel: to create the pipeline when needed to create the source sequence, and then create the target, when closed, to close off the target and then source 
98          fos.close ();
 99          fis.close ();
 100          . the System OUT .println ( " -------- -------- buffer " );
 101          // the video from one location to another location, use byte transport stream
 102          // source 
103          file fileold1 = new new file ( " D: \\ \\ txt77.txt TTF text \\ " );
 104          // target file 
105         Filenew1 = File new new File ( " D: \\ \\ txt.txt TTF text \\ " );
 106          // requires two files associated conduit 
107          the FileInputStream FIS1 = new new the FileInputStream (fileold1);
 108          a FileOutputStream f OS1 = new new a FileOutputStream ( filenew1);
 109          // byte stream into a stream buffer 
110          BufferedInputStream BIS = new new BufferedInputStream (FIS1);
 111          BufferedOutputStream the BOS = new new BufferedOutputStream the (f OS1);
 112          // transmission process, is read out in fis fos 
113          int= LEN1 0 ;
 114          byte Rate [] = new new  byte [ 1024 ];
 115          the while ((LEN1 bis.read = (Rate)) = -! . 1 ) {
 1 16              bos.write (Rate, 0   , LEN1);
 117              the System. OUT .print (LEN1 + "  " );
 1 18          }
 119          // Close channel: to create the pipe when the need to create the source sequence, and then create the target, when closed, to close off the target and then source, and then close the close byte buffer 
120          BOS .close ();
 121          fos.close ();
 122          bis.close ();
 123         fis.close();
124     }
125 }

 

Guess you like

Origin www.cnblogs.com/qsy0021/p/11361630.html