BufferedReader buffReader = new BufferedReader(new InputStreamReader(
new FileInputStream("d:\\test.txt"));
String readLine = null;String[] fields = null;
while ((readLine = buffReader.readLine()) != null) {
//分解字符
fields = readLine.split("\t");
} }

解决方案 »

  1.   

    把上面的readLine.split("\t")改成 readLine.split(",")就可以了
    这样fields数组里面存放的就是你想要的12345
      

  2.   

    你那样的算法,把逗号都用readInt读出来最后那个异常是因为文件已经结束
      

  3.   

    谢谢杉叶的回答,fields是String类型的,我想要int类型的,不知道怎么转换?还有我的数据量很大我希望能一个一个读。因为我想每100个放入一个数组。无论如何太感谢了!!
      

  4.   

    System.out.println(rafFile.readInt()+"\n")有问题,readInt()是一次读4个字节。import java.io.*;
    public class readfile
    {
    public static void main(String args [])throws IOException
    {
    char c =0;
    System.out.println(" start here!\n");
    File readFrom = new File("d:\\test.txt");
    if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
        {
       RandomAccessFile rafFile = new RandomAccessFile(readFrom,"rw");
       long length=rafFile.length();
       System.out.println("file length"+ length +"\n");
        for (int i=0;i<length;i++)
       {
    c=(char)rafFile.read();
       System.out.println(c+"\n");
       }
        }
     }
    }
    我帮你改了,你试试
      

  5.   

    要int的,用Integer类的parshInt方法转化一下!
      

  6.   

    这还不简单,我又改了点,你再试
    import java.io.*;
    public class readfile
    {
    public static void main(String args [])throws IOException
    {
    char c =0;
    System.out.println(" start here!\n");
    File readFrom = new File("d:\\test.txt");
    if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
        {
       RandomAccessFile rafFile = new RandomAccessFile(readFrom,"rw");
       long length=rafFile.length();
       System.out.println("file length"+ length +"\n");
        for (int i=0;i<length;i++)
       {
    c=(char)rafFile.read();
    if(c==',') System.out.println();
       System.out.print(c);
       }
        }
     }
    }
      

  7.   

    我把格式又调好看了点,你试这个
    import java.io.*;
    public class readfile
    {
    public static void main(String args [])throws IOException
    {
    char c =0;
    System.out.println(" start here!\n");
    File readFrom = new File("d:\\test.txt");
    if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead())
        {
       RandomAccessFile rafFile = new RandomAccessFile(readFrom,"rw");
       long length=rafFile.length();
       System.out.println("file length"+ length +"\n");
        for (int i=0;i<length;i++)
       {
    c=(char)rafFile.read();
    if(c=='') {
    System.out.println();
    System.out.println(c);
    continue;
    }
    System.out.print(c);
       }
        }
     }
    }
      

  8.   

    云娜你说的对,但是我要的是int型的数字,对这些数字进行处理.
      

  9.   

    按你要求改了,所有的数字都保存在数组result里,帮你改了好几遍了,我要求加分^-^
    import java.io.*;
    public class readfile {
    public static void main(String args [])throws IOException {
    char c = 0;
    int count = 1;
    String s = "";
    System.out.println(" start here!\n");
    File readFrom = new File("d:\\test.txt");
    if(readFrom.isFile()&&readFrom.canWrite()&&readFrom.canRead()) {
    RandomAccessFile rafFile = new RandomAccessFile(readFrom,"rw");
    long num = rafFile.length();
    System.out.println("file length"+ num +"\n");
    for (int j = 0;j < num;j++) {
    c=(char)rafFile.read();
    if(c == ',') {
    count += 1;
    }
    }
    int[] result = new int[count];
    int k = 0;
    rafFile.seek(0);
    for (int i = 0;i < num;i++) {
    c=(char)rafFile.read();
    if(c == ',') {
    System.out.println();
    System.out.println(c);
    result[k++] = new Integer(s).intValue();
    s = "";
    continue;
    }
    System.out.print(c);
    s = s+c;
    }
    }
    }
    }