import java.io.*;public class collect {/*** @param args*/public static void main(String[] args) throws Exception {// TODO Auto-generated method stubFile f=new File("c:\\france.txt");RandomAccessFile mm = new RandomAccessFile(f,"rw");Item[] qq= new Item[1000];for (int i = 0; i < 1000; i++) {qq[i] = new Item();}for (int h = 0; h < 10; h++) {qq[h].title=mm.readLine();qq[h].content=mm.readLine()+"\n"+mm.readLine()+"\n"+mm.readLine();qq[h].getInfo();}}class Item{String title;String content;public void getInfo(){System.out.println(title);System.out.println(content);}}刚刚学,上面搞来搞去不知道错哪了.....路过帮帮忙
2 回答
holdtom
TA贡献1805条经验 获得超10个赞
import java.io.*;
public class Collect {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
File f=new File("c:\\france.txt");
RandomAccessFile mm = new RandomAccessFile(f,"rw");
Item[] qq= new Item[1000];
for (int i = 0; i < 1000; i++) {
qq[i] = new Item();
}
for (int h = 0; h < 10; h++) {
qq[h].title=mm.readLine();
qq[h].content=mm.readLine()+"\n"+mm.readLine()+"\n"+mm.readLine();
qq[h].getInfo();
}
}
}//此处再加一个大括号,并且不能在最后加大括号,除非你把下面的类当成静态内部类
class Item{
String title;
String content;
public void getInfo(){
System.out.println(title);
System.out.println(content);
}
}
添加回答
举报
0/150
提交
取消