SUN认证考试知识点:java读取文件内容的函数

时间:2024-05-30 11:38:31 SUN认证 我要投稿
  • 相关推荐

SUN认证考试知识点:java读取文件内容的函数

  public static String readFile(String fileName) {

SUN认证考试知识点:java读取文件内容的函数

  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()));

  }

  }

《SUN认证考试知识点:java读取文件内容的函数.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

【SUN认证考试知识点:java读取文件内容的函数】相关文章:

sun java认证考试介绍10-23

Sun java认证考试答案11-06

Sun Java认证考试科目08-30

sun java认证考试报考指南10-18

SUN JAVA认证介绍08-09

SUN认证考试知识点:java servlet生命周期09-25

Sun认证Java开发员考试介绍10-09

sun认证考试:Java.io的使用08-23

Sun Java认证考试教材教辅09-13

Sun java认证考试真题答案09-25

在线咨询

SUN认证考试知识点:java读取文件内容的函数

  public static String readFile(String fileName) {

SUN认证考试知识点:java读取文件内容的函数

  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()));

  }

  }