java读取txt文件中的账号密码 并存入数组
展开全部
int size = 6;
int [] a = new int [size];
int [] b = new int [size];
float [] c = new float [size];
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String line = br.readLine();
int i=0;//从0开始
while(line!=null){
String [] numbers = line.split(" ");//这个是跳过空格
a[i]=Integer.valueOf(numbers[0]);
b[i]=Integer.valueOf(numbers[1]);
c[i]=Float.valueOf(numbers[2]);
i++;
line = br.readLine();
}
for(int num:a)System.out.print(num+" ");
System.out.println();
for(int num:b)System.out.print(num+" ");
System.out.println();
for(float num:c)System.out.print(num+" ");
br.close();
//亲自写的哦~...一定要给分我啊~~~~
//补充下注意 文件路径! 我这个是和src在同一级 就是工程目录下..
int [] a = new int [size];
int [] b = new int [size];
float [] c = new float [size];
BufferedReader br = new BufferedReader(new FileReader("test.txt"));
String line = br.readLine();
int i=0;//从0开始
while(line!=null){
String [] numbers = line.split(" ");//这个是跳过空格
a[i]=Integer.valueOf(numbers[0]);
b[i]=Integer.valueOf(numbers[1]);
c[i]=Float.valueOf(numbers[2]);
i++;
line = br.readLine();
}
for(int num:a)System.out.print(num+" ");
System.out.println();
for(int num:b)System.out.print(num+" ");
System.out.println();
for(float num:c)System.out.print(num+" ");
br.close();
//亲自写的哦~...一定要给分我啊~~~~
//补充下注意 文件路径! 我这个是和src在同一级 就是工程目录下..
追问
我是需要把账号密码分离出来 然后做循环登陆的
2016-06-04 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
public static void main(String[] args) throws Exception {
File file = new File("src/test.txt");
double[] a = getLineFromTxt(file," ");
for(int i = 0; i< a.length; i++){
System.out.println("a["+i+"] = "+a[i]);
}
}
test中的数据以空格隔开 12 32 32.02
public static double[] getLineFromTxt(File file, String split) throws Exception{
BufferedReader br = new BufferedReader(new FileReader(file));
String firstLine = br.readLine(); //就读第一行哦
String[] arrs = firstLine.split(" ");
//将字符数组转为double数组
double[] arr = new double[arrs.length];
for(int i = 0; i< arr.length; i++){
arr[i] = Double.parseDouble(arrs[i]);
}
if(br!= null){
br.close();
br = null;
}
return arr;
}
File file = new File("src/test.txt");
double[] a = getLineFromTxt(file," ");
for(int i = 0; i< a.length; i++){
System.out.println("a["+i+"] = "+a[i]);
}
}
test中的数据以空格隔开 12 32 32.02
public static double[] getLineFromTxt(File file, String split) throws Exception{
BufferedReader br = new BufferedReader(new FileReader(file));
String firstLine = br.readLine(); //就读第一行哦
String[] arrs = firstLine.split(" ");
//将字符数组转为double数组
double[] arr = new double[arrs.length];
for(int i = 0; i< arr.length; i++){
arr[i] = Double.parseDouble(arrs[i]);
}
if(br!= null){
br.close();
br = null;
}
return arr;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询