IOUtil.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:2k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.common;
- import java.io.*;
- import org.apache.commons.logging.LogFactory;
- import org.apache.commons.logging.Log;
- public class IOUtil {
- private static Log log = LogFactory.getLog(IOUtil.class);
- private String contentType =
- "<%@ page contentType="text/html; charset=GBK" %>";
- public IOUtil() {
- }
- public String readFile(String path) {
- File file = null;
- FileReader fr = null;
- BufferedReader br = null;
- file = new File(path);
- StringBuffer sb = new StringBuffer();
- try {
- fr = new FileReader(file);
- br = new BufferedReader(fr);
- String record = null;
- record = br.readLine();
- while ((record = br.readLine()) != null) {
- sb.append(record);
- }
- } catch (FileNotFoundException ex) {
- log.error(ex.getMessage(), ex);
- } catch (IOException ex) {
- log.error(ex.getMessage(), ex);
- } finally {
- try {
- br.close();
- fr.close();
- file = null;
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- }
- }
- return sb.toString();
- }
- public void writeFile(String content,String path) {
- FileWriter fw = null;
- PrintWriter out = null;
- try {
- fw = new FileWriter(path);
- out = new PrintWriter(fw);
- out.println(this.contentType);
- out.println(content);
- } catch (IOException ex) {
- log.error(ex.getMessage(), ex);
- } finally {
- try {
- out.close();
- fw.close();
- } catch (Exception ex) {
- log.error(ex.getMessage(), ex);
- }
- }
- }
- }