fileutil.java

来自「struts+spring+hibernate自创框架」· Java 代码 · 共 39 行

JAVA
39
字号
package com.pegasus.framework.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.pegasus.framework.exception.NestedRuntimeException;

public class FileUtil {

	public static String readFile(String filename) throws FileNotFoundException, IOException {
		return readFile(new File(filename));
	}

	public static String readFile(File file) {
		InputStream inputStream = null;
		String result = "";
		try {
			inputStream = new FileInputStream(file);
			result = StreamUtil.readStream(inputStream);
		} catch (IOException e) {
			throw new NestedRuntimeException("readFile", e);
		} catch (Exception e) {
			throw new NestedRuntimeException("readFile", e);
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					throw new NestedRuntimeException("readFile", e);
				}
			}
		}
		return result;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?