免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1277 | 回复: 0
打印 上一主题 下一主题

Jjava读取文件内容的函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-07 19:22 |只看该作者 |倒序浏览
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[i] + "\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[i]. substring(0, temp[i]. indexOf(", ")),  temp[i]. substring(temp[i]. indexOf(", ")+1, temp[i]. length()));
  }
  }文章由 besunyen.tk 碧生源减肥茶效果怎么样 整理,收集辛苦,希望能保留出处。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP