Reader_Writer.java
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:2k
源码类别:

OA系统

开发平台:

Java

  1. package control.Filecontrol;
  2. import java.io.*;
  3. import java.util.*;
  4. import java.lang.*;
  5. public class Reader_Writer {
  6.     private String filename;
  7.     private String fin;
  8.     public Reader_Writer() {
  9.     }
  10.     //参数为存路径的字符串这个方法用来读取参数中路径所指向的文件
  11.     public String ReadFile(String path){
  12.         try{
  13.             this.filename = path;
  14.             BufferedReader in = new BufferedReader(new FileReader(filename));
  15.             String temp="";
  16.             String context="";
  17.             while((temp=in.readLine())!=null){
  18.                 context  = context + temp;
  19.             }
  20.             this.fin = context;
  21.             in.close();
  22.         }catch(Exception e){
  23.             e.printStackTrace();
  24.         }
  25.         return fin;
  26.     }
  27.     //用这个方法向path写入内容为context中所存的信息
  28.     public void WriteFile(String path,String context){
  29.         this.filename = path;
  30.         try{
  31.           PrintWriter writer = new PrintWriter(new BufferedWriter(new
  32.                   FileWriter(filename)));
  33.           writer.write(context);
  34.           writer.close();
  35.       }catch(Exception e){
  36.           e.printStackTrace();
  37.       }
  38.     }
  39.     //创建文件夹
  40.     public void mkdir(String mkdirName)
  41.  {
  42.      try
  43.      {
  44.          File  dirFile = new File(mkdirName);
  45.          boolean bFile   = dirFile.exists();
  46.          if( bFile == true )
  47.          {
  48.            }
  49.          else
  50.          {
  51.             bFile = dirFile.mkdir();
  52.             if( bFile == true )
  53.             {
  54.             }
  55.             else
  56.             {
  57.                 System.exit(1);
  58.             }
  59.          }
  60.      }
  61.      catch(Exception err)
  62.      {
  63.          err.printStackTrace();
  64.      }
  65.  }
  66. }