标题:
Jjava读取文件内容的函数
[打印本页]
作者:
qingqing3721
时间:
2011-5-7 18:44
标题:
Jjava读取文件内容的函数
public static String readFile(String fileName) {
String output = "";
File file = new File(fileName);
if (file. exists()) {
if (file. isFile()) {
try {
BufferedReader input = new BufferedReader(new FileReader(
file));
StringBuffer buffer = new StringBuffer();
String text;
while ((text = input. readLine()) != null)
buffer. append(text + "\n");
output = buffer. toString();
} catch (IOException ioException) {
System. err. println("File Error!");
}
} else if (file. isDirectory()) {
String[] dir = file. list();
output += "Directory contents:\n";
for (int i = 0; i < dir. length; i++) {
output += dir
+ "\n";
}
}
} else {
System. err. println("Does not exist!");
}
return output;
}
public static void main(String args[]) {
Map ab = new HashMap();
String str = readFile("C:/AbCircuitInfo");
String[] temp=str. split("\\n");
for (int i = 0; i < temp. length; i++) {
ab. put(temp
. substring(0, temp
. indexOf(", ")), temp
. substring(temp
. indexOf(", ")+1, temp
. length()));
}
}文章由 shoubiqing.tk 减肥胶囊配方 整理,收集辛苦,希望能保留出处。
欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/)
Powered by Discuz! 6.0.0