当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
计算机二级辅导:运用JAVA读取txt文件
发布时间:2010/4/5 17:35:38 来源:城市学习网 编辑:admin
  package com.b;
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileReader;
  import java.io.IOException;
  /**
  */
  public class Utils {
  /**
  * 读取数据
  */
  public String ReadDate() {
  String url = "c:/data.txt";
  String strs = "";
  try {
  FileReader read = new FileReader(new File(url));
  StringBuffer sb = new StringBuffer();
  char ch = new char[1024];
  int d = read.read(ch);
  while(d!=-1){
  String str = new String(ch,0,d);
  sb.append(str);
  d = read.read(ch);
  }
  System.out.print(sb.toString());
  String a = sb.toString().replaceAll("@@@@@", ",");
  strs = a.substring(0,a.length()-1);
  } catch (FileNotFoundException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  }
  return strs ;
  }
  public static void main(String a)
  {
  Utils util = new Utils();
  String cc = util.ReadDate();
  System.out.println("result...."+cc);
  }
  }
  :
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved