如何解决我需要正确的String放在“ new FileReader” stringpath“”中的括号中
这是我的Android Studio项目的功能。
我需要正确的String才能放在“ new FileReader(“ stringpath”)”中的括号中,而我尝试的所有方法均无效。
那是我的代码:
private ArrayList<Spieler> generiereSpieler(int anzahl){
ArrayList<Spieler> spielerListe = new ArrayList<>();
ArrayList<String> spielerListeString = new ArrayList<>();
BufferedReader file = null;
try{
file = new BufferedReader(new FileReader("spieler.csv"));
while(file.ready()){
spielerListeString.add(file.readLine());
}
} catch(NullPointerException | IOException e){
System.out.println("FEHLER: Konnte CSV-Datei (Spieler) nicht einlesen");
} finally {
try{
file.close();
} catch(NullPointerException | IOException e){
System.out.println("FEHLER: Konnte CSV-Datei (Spieler) nicht schließen");
}
}
try{
StringTokenizer stringTokenizer = null;
Random random = new Random();
int spielerAnzahl = spielerListeString.size();
int spielerIndex = 1; //TODO
Spieler spieler;
for(int index = 0; index < anzahl; index++){
spielerIndex = random.nextInt(spielerAnzahl);
stringTokenizer = new StringTokenizer(spielerListeString.get(spielerIndex),",");
spieler = new Spieler(stringTokenizer.nextToken(),stringTokenizer.nextToken(),null);
spielerListe.add(spieler);
}
} catch(NullPointerException | NoSuchElementException e){
System.out.println("FEHLER: Konnte Liste (Spieler) nicht verarbeiten");
} catch (IllegalArgumentException e){
System.out.println("FEHLER: IllegalArgumentException");
e.printStackTrace();
}
return spielerListe;
}
找不到文件?我需要放什么东西?
我需要将文件放在资源或原始文件夹中,如何获取其路径?
解决方法
尝试将“ spieler.csv”文件以及源文件夹放在项目文件夹中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。