欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

java读txt文件

程序员文章站 2022-05-31 10:41:43
...

/* 来于互联网

  * 读取char

  */

  private String readtxt() throws IOException{

  BufferedReader br=new BufferedReader(new FileReader("d:/sql.txt"));

  String str="";

  String r=br.readLine();

  while(r!=null){

  str+=r;

  r=br.readLine();

  }

  return str;

  }

  Java代码

  /*

  * 读取char

  */

  private String readtxt() throws IOException{

  BufferedReader br=new BufferedReader(new FileReader("d:/sql.txt"));

  String str="";

  String r=br.readLine();

  while(r!=null){

  str+=r;

  r=br.readLine();

  }

  return str;

  }

  Java代码

  /*

  * 读取char

  */

  private String readtxt2() throws IOException{

  String str="";

  FileReader fr=new FileReader("d:/sql.txt");

  char[] chars=new char[1024];

  int b=0;

  while((b=fr.read(chars))!=-1){

  str+=String.valueOf(chars);

  }

  return str;

  }

  Java代码

  /*

  * 读取char

  */

  private String readtxt2() throws IOException{

  String str="";

  FileReader fr=new FileReader("d:/sql.txt");

  char[] chars=new char[1024];

  int b=0;

  while((b=fr.read(chars))!=-1){

  str+=String.valueOf(chars);

  }

  return str;

  }

  Java代码

  /*

  * 读取bytes

  */

  private Byte[] readtxt3() throws IOException{

  InputStream input=new FileInputStream("d:/sql.txt");

  byte[] b=new byte[1024];

  ArrayList<Byte> lsbytes=new ArrayList<Byte>();

  int n=0;

  while((n=input.read(b))!=-1){

  for(int i=0;i<n;i++){

  lsbytes.add(b[i]);

  }

  }

  return (Byte[])(lsbytes.toArray());

  }

  Java代码

  /*

  * 读取bytes

  */

  private Byte[] readtxt3() throws IOException{

  InputStream input=new FileInputStream("d:/sql.txt");

  byte[] b=new byte[1024];

  ArrayList<Byte> lsbytes=new ArrayList<Byte>();

  int n=0;

  while((n=input.read(b))!=-1){

  for(int i=0;i<n;i++){

  lsbytes.add(b[i]);

  }

  }

  return (Byte[])(lsbytes.toArray());

  }