如文本中的数据为: 11
12
13读到数组中为:
a[0] : 11
a[1] : 12
a[2] : 13用JAVA实现,谢谢。
12
13读到数组中为:
a[0] : 11
a[1] : 12
a[2] : 13用JAVA实现,谢谢。
解决方案 »
- Java高手看过来(在下小小C#程序员一名)
- 怎么样在java里实现在命令行使用自己命名命令?
- (学JAVA的都进来.........)runtime exception与Compile time error有什么区别!
- 如何把Swing组件上的显示画面保存成一个图象image对象
- 为什么是这个结果 ,怪事。感谢。
- 有关华为JAVA工程师面试的问题
- 记事本好,editplus好,UltraEdit好,还是JCreator好 ?(发表意见者有分)
- 关于转型,Object的作用及用法问题
- 可执行文件的问题?
- 各位大侠:如何学JAVA,还有买什么书,需要安装什么环境?....
- "a|b".split("|").length
- 听说jdk1.6对线程池有个什么优化来着,有人知道么?
然后用for循环添加到数组里!LZ 还是自己动手吧! 写过一遍 感觉就不一样了PS: LZ 及时结贴!
FileReader file;
try {
file = new FileReader("D:/data.txt");
BufferedReader in = new BufferedReader(file);
while (in.ready()) {
array[i] = in.readline();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}给出一个框架,楼主参考。。
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
public class Ansewer16
{
public static void main(String[] ags) throws Exception
{
BufferedReader br=new BufferedReader(new FileReader(new File("c:"+File.separator+"11.txt")));
int[] a=new int[3];
int n=0;
String s="";
while((s=br.readLine())!=null)
{
a[n++]=Integer.parseInt(s);
}
for(int in:a)
System.out.println(in);
}
}
import java.util.ArrayList;
import java.util.List;public class Test{
public static void main(String [] args)throws Exception{
List<String> sList = new ArrayList<String>();
File file = new File("你的文件所在路径");//文件
BufferedReader br = new BufferedReader(new FileReader(file));
String s = null;
while((s=br.readLine())!=null)//读文件
sList.add(s);
int arr[] = new int[sList.size()];//创建数组
for(int i=0;i<arr.length;i++){
arr[i] = Integer.parseInt(sList.get(i));//给数组赋值
}
for(int t : arr)//输出结果
System.out.println(t);
br.close();
System.out.println("请楼主给分吧!");
}
}