java 读取数组_如何在Java中从文件读取数据到数组?

我需要一些帮助从文本文件中读取数据到我的ArrayList.创建并将ArrayList放入文本文件的第一部分非常有效.我只是在“标记”区域的最后需要一些帮助.

请注意,某些标识符使用我的母语.

public class ContAngajat {

String username;

String password;

}

public class CreazaCont {

// creating the arraylist and putting it into a file

public static void ang(String args[]) {

ArrayList angajati=new ArrayList(50);

Scanner diskScanner = new Scanner(in);

Scanner forn = new Scanner(in);

int n;

out.print("Introduceti numarul de conturi noi care doriti sa le introduceti: ");

n=forn.nextInt();

out.println();

try{

FileWriter fw = new FileWriter("ConturiAngajati.txt", true);

for(int i=0; i

ContAngajat cont = new ContAngajat();

out.print("Username: ");

cont.username=diskScanner.nextLine();

out.print("Password: ");

cont.password=diskScanner.nextLine();

angajati.add(cont);

fw.write(cont.username + " ");

fw.write(cont.password +"|");

}

fw.close();

}

catch(IOException ex){

System.out.println("Could not write to file");

System.exit(0);

}

for (int i=0; i

out.println("username: " + angajati.get(i).username + " password: " +angajati.get(i).password );

}

}

// HERE I'M TRING TO GET THE ARRAYLIST OUT OF THE FILE

public static void RdAng(String args[]) {

ArrayList angajati=new ArrayList(50);

ContAngajat cont = new ContAngajat();

int count,i2,i;

try{

FileReader fr = new FileReader("ConturiAngajati.txt");

BufferedReader br = new BufferedReader(fr);

String line = "";

while((line=br.readLine())!=null) {

String[] theline=line.split("|");

count=theline.length;

for(i=0;i

String[] theword = theline[i].split(" ");

}

}

for(i2=0;i2

ContAngajat contrd = new ContAngajat();

// "ERROR" OVER HERE

for (int ird=0; ird

cont.username=theword[0];

cont.password=theword[1];

// they keep telling me "theword cannot be resolved" whenever i try to run this

}

angajati.add(contrd);

}

}

catch(IOException ex){

System.out.println("Could not read to file");

System.exit(0);

}

}

}

编译错误是无法解决的.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值