package cn
import java
import java
public class FileAccess {
public static String readAllText(String fileName) throws IOException {
StringBuffer sb = new StringBuffer();
char[] buf = new char[
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
while(br
sb
}
return sb
}
public static String readAllText(String fileName
StringBuffer sb = new StringBuffer();
char[] buf = new char[
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)
while(br
sb
}
return sb
}
public static String[] readAllLines(String fileName) throws IOException {
ArrayList<String> lines = new ArrayList<String>();
String s;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
while ((s = br
lines
br
return lines
}
public static String[] readAllLines(String fileName
ArrayList<String> lines = new ArrayList<String>();
String s;
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)
while ((s = br
lines
br
return lines
}
public static void writeAllText(String fileName
PrintWriter pw = new PrintWriter(new FileOutputStream(fileName));
pw
pw
pw
}
public static void writeAllText(String fileName
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName)
pw
pw
pw
}
public static void writeAllLines(String fileName
PrintWriter pw = new PrintWriter(new FileOutputStream(fileName));
for(String s : lines)
pw
pw
pw
}
public static void writeAllLines(String fileName
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fileName)
for(String s : lines)
pw
pw
pw
}
public static void writeObject(String fileName
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName));
oos
oos
oos
}
public static Object readObject(String fileName) throws IOException
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName));
Object ob = ois
ois
return ob;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25872.html