Reader_Writer.java
资源名称:bangong.rar [点击查看]
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:2k
源码类别:
OA系统
开发平台:
Java
- package control.Filecontrol;
- import java.io.*;
- import java.util.*;
- import java.lang.*;
- public class Reader_Writer {
- private String filename;
- private String fin;
- public Reader_Writer() {
- }
- //参数为存路径的字符串这个方法用来读取参数中路径所指向的文件
- public String ReadFile(String path){
- try{
- this.filename = path;
- BufferedReader in = new BufferedReader(new FileReader(filename));
- String temp="";
- String context="";
- while((temp=in.readLine())!=null){
- context = context + temp;
- }
- this.fin = context;
- in.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- return fin;
- }
- //用这个方法向path写入内容为context中所存的信息
- public void WriteFile(String path,String context){
- this.filename = path;
- try{
- PrintWriter writer = new PrintWriter(new BufferedWriter(new
- FileWriter(filename)));
- writer.write(context);
- writer.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- //创建文件夹
- public void mkdir(String mkdirName)
- {
- try
- {
- File dirFile = new File(mkdirName);
- boolean bFile = dirFile.exists();
- if( bFile == true )
- {
- }
- else
- {
- bFile = dirFile.mkdir();
- if( bFile == true )
- {
- }
- else
- {
- System.exit(1);
- }
- }
- }
- catch(Exception err)
- {
- err.printStackTrace();
- }
- }
- }