Exemplo n.º 1
0
  /**
   * 文件转换成一维数组
   *
   * @return
   */
  public static String[] fileToDimArr(String input_file) throws Exception {
    FileReader fr = new FileReader(new File(input_file));
    BufferedReader br = new BufferedReader(fr);
    String line = "";

    ArrayList<String> dataList = new ArrayList<String>();

    while ((line = br.readLine()) != null) {
      line = line.trim();
      // System.out.println("line:"+line);
      if (!(SSO.tnoe(line))) {
        continue;
      }

      dataList.add(line);
    }

    br.close();
    fr.close();

    String[] dda = new String[dataList.size()];
    for (int i = 0; i < dda.length; i++) {
      dda[i] = dataList.get(i);
    }

    return dda;
  }
Exemplo n.º 2
0
  /**
   * 文件转换成二维数组
   *
   * @return
   */
  public static String[][] fileToDoubleDimArr(String input_file, String seprator) throws Exception {
    FileReader fr = new FileReader(new File(input_file));
    BufferedReader br = new BufferedReader(fr);
    String line = "";

    String field_info = "";
    String field = "";

    line = br.readLine();
    if (!(SSO.tnoe(line))) {
      return null;
    }
    line = line.trim();
    String[] seg_arr = null;
    seg_arr = line.split(seprator);

    ArrayList<String[]> dataList = new ArrayList<String[]>();
    int field_num = seg_arr.length;
    dataList.add(seg_arr);

    while ((line = br.readLine()) != null) {
      line = line.trim();
      // System.out.println("line:"+line);
      if (!(SSO.tnoe(line))) {
        continue;
      }
      seg_arr = line.split(seprator);
      //  System.out.println("seg_arr.length:"+seg_arr.length);
      if (seg_arr.length != field_num) {
        continue;
      }
      dataList.add(seg_arr);
    }
    br.close();
    fr.close();

    String[][] ddda = new String[dataList.size()][field_num];
    for (int i = 0; i < ddda.length; i++) {
      ddda[i] = dataList.get(i);
    }

    return ddda;
  }
Exemplo n.º 3
0
  /**
   * 文件各行存入arraylist中
   *
   * @param input_file
   * @return
   * @throws Exception
   */
  public static ArrayList<String> fileToArrayList(String input_file) throws Exception {
    FileReader fr = new FileReader(new File(input_file));
    BufferedReader br = new BufferedReader(fr);
    String line = "";

    ArrayList<String> dataList = new ArrayList<String>();

    while ((line = br.readLine()) != null) {
      line = line.trim();
      // System.out.println("line:"+line);
      if (!(SSO.tnoe(line))) {
        continue;
      }

      dataList.add(line);
    }

    br.close();
    fr.close();

    return dataList;
  }