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");
} }
new FileInputStream("d:\\test.txt"));
String readLine = null;String[] fields = null;
while ((readLine = buffReader.readLine()) != null) {
//分解字符
fields = readLine.split("\t");
} }
这样fields数组里面存放的就是你想要的12345
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");
}
}
}
}
我帮你改了,你试试
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);
}
}
}
}
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);
}
}
}
}
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;
}
}
}
}