比如记事本里有三行三列数字:1 2 3
4 5 6
7 8 9
怎么用java程序把里面的数据分别读出来再赋值给其他变量?比如我想把4,5,6依次拿出来赋值给int a,b,c?希望大家能帮忙,谢过先
4 5 6
7 8 9
怎么用java程序把里面的数据分别读出来再赋值给其他变量?比如我想把4,5,6依次拿出来赋值给int a,b,c?希望大家能帮忙,谢过先
解决方案 »
- java File 类中的 mkdirs 问题。(剩余空间不足以建立目录,怎么检测出来呢?)
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 iReport分页问题
- 泛型的基础概念模糊。。。
- 有谁用过cardme这个插件吗(导入vcard联系)
- 如何用JDBC得到表中的字段名?
- 请高手指教:正在研究java.lang.reflect.Proxy类,有n事不明
- 正则高手进
- 关于private和static的不同的问题
- 看看这几个APPLET程序。(在线等2小时)
- 为什么JBuilder 6在编写数据库程序是CPU的占用率达到100%,具体定位在java.exe
- 100分求答案.在android中绘制圆形
- 小白一枚,请教关于包装类中字符串类型转换成基本数据类型的问题
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;public class Test { public static void main(String[] args) {
File f = new File("E:/A/Score.txt"); try {
BufferedReader dis = new BufferedReader(new FileReader(f));
String line = null;
while ((line = dis.readLine()) != null) {
String[] arr = line.trim().split("\\s+");
int a = Integer.parseInt(arr[0]);
int b = Integer.parseInt(arr[1]);
int c = Integer.parseInt(arr[2]);
}
dis.close(); } catch (IOException e) {
e.printStackTrace();
}
}}
class Test{
public static void main(String[] args)throws IOException{
BufferedReader reader = new BufferedReader(new FileReader("test.txt"));
String line = reader.readLine();
line = reader.readLine();
String[] num = line.split("\\s");
int a = Integer.parseInt(num[0]);
int b = Integer.parseInt(num[1]);
int c = Integer.parseInt(num[2]);
reader.close();
System.out.println(a+" "+b+" "+c);
}}
File file=new File("file1.txt");
try{
FileReader fd=new FileReader(file);
BufferedReader br=new BufferedReader(fd);
String txt="";
String str="";
while((str=br.readLine())!=null){
txt+=str;
}
br.close();
fd.close();
char[]ch=txt.toCharArray();
int a=Integer.parseInt(String.valueOf(ch[3]));
int b=Integer.parseInt(String.valueOf(ch[4]));
int c=Integer.parseInt(String.valueOf(ch[5]));
System.out.println(a+" "+b+" "+c);
}catch(Exception e){
e.printStackTrace();
}
}