急救小弟
import java.io.*;
public final class myFileF {
public static int i;
public static void main(String[] args)throws IOException {
FileInputStream fis = null;
byte[] b = null;
String s = "";
String [] t=null;
int row[]=null;
int flag=0;
try {
File f = new File("E:\\方案1.ini"); //任意读取一个文件的内容
b = new byte[ (int) f.length()];
fis = new FileInputStream(f);
fis.read(b);
s=new String(b);
System.out.println("s是:"+s);
for(i=0;i<f.length();i++){
int temp = 0;
if(b[i]=='\n')
{
row[flag]=i;//为什么不能这样?我想得出字符中每个回车的位置
flag++;
}
}
t=new String[flag];
fis.close();
}
catch (Exception e) {
;
}
}
}
//请问如何将s每到一个'\n' 将前面的字符串转为单独的字符串存到String [] tt中
[解决办法]
import java.io.*;
import java.util.StringTokenizer;
public final class myFileF {
public static void main(String[] args)throws IOException {
FileInputStream fis = null;
byte[] b = null;
String s = "";
String [] t = null;
int row[]=null;
int flag=0;
try {
File f = new File("E:\\11.ini");
b = new byte[(int) f.length()];
fis = new FileInputStream(f);
fis.read(b);
s=new String(b);
StringTokenizer st = new StringTokenizer(s,"\n");
int i=0;
t = new String[st.countTokens()];
while(st.hasMoreTokens())
{
t[i] = (String)st.nextElement();
i++;
}
fis.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
不知道这样是否满足你的要求。
还有,个人觉得你的代码编写有点混乱。