📄 fileio.java
字号:
package com.laoer.comm.util;
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* <p>Title: 天乙软件工作室公共包</p>
* <p>Description: 天乙软件工作室公共包</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: 天乙软件工作室[LAOER.COM/TIANYISOFT.NET]</p>
* @author 龚天乙(Laoer)
* @version 1.0
*/
public class FileIO {
private static final Log logger = LogFactory.getLog(FileIO.class);
public static String readFile(String filePath) {
String info = "";
try {
File f = new File(filePath);
if (f.exists()) {
FileInputStream bw = new FileInputStream(f);
int len = bw.available();
byte[] str = new byte[len];
if (bw.read(str) == -1) {
info = "";
}
else {
info = new String(str);
}
bw.close();
bw = null;
}
f = null;
}
catch (IOException e) {
logger.error(e);
}
return info;
}
public static String readFile(String filePath, String charset) {
String info = "";
try {
File f = new File(filePath);
if (f.exists()) {
FileInputStream bw = new FileInputStream(f);
int len = bw.available();
byte[] str = new byte[len];
if (bw.read(str) == -1) {
info = "";
}
else {
info = new String(str, charset);
}
bw.close();
bw = null;
}
f = null;
}
catch (IOException e) {
logger.error(e);
}
return info;
}
public static void writeFile(String msg, String filePath) {
try {
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
FileOutputStream wf = new FileOutputStream(filePath);
wf.write(msg.getBytes());
wf.close();
file = null;
wf = null;
}
catch (IOException e) {
logger.error(e);
}
}
public static void writeFile(String msg, String filePath, String charset) {
try {
File file = new File(filePath);
if (file.exists()) {
file.delete();
}
FileOutputStream wf = new FileOutputStream(filePath);
wf.write(msg.getBytes(charset));
wf.close();
file = null;
wf = null;
}
catch (IOException e) {
logger.error(e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -