我正在创建一个应用程序,在其中列出教师和他们在我的学校所做的所有事情。我有3个文件,一个教师类,它是一个可以容纳7个字符串变量的对象,一个TeacherList类,在这里我接收.txt文件并从中提取数据以形成教师。这是我的问题在哪里,我应该在哪里放置文件?继承人TeacherList代码:如何在Android应用程序中访问简单的txt文件?
package com.mthebron.mthapp;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class TeacherList {
public static Teacher[] MakeList() throws FileNotFoundException{
Teacher[] teachers=new Teacher[71];
File list=new File("C:/Users/Gareth/Desktop/TeacherInformation.txt");
Scanner iScanner=new Scanner(list);
StringBuilder teachersBuilder=new StringBuilder();
while(iScanner.hasNext()) {
teachersBuilder.append(iScanner.nextLine());
teachersBuilder.append("\n");
}
String fullList=teachersBuilder.toString();
String[] seperatedList=fullList.split("'");
String[] blah=seperatedList[0].split("\n");
String temp=blah[0].substring(3, 9);
String name=temp;
String department=blah[1];
String planning=blah[2];
String club=blah[3];
String sport=null;
String email=blah[5];
String website=null;
teachers[0]=new Teacher(name, department, planning, club, sport, email, website);
System.out.println(teachers[0].getSportsCoached());
for (int i = 1; i < seperatedList.length; i++) {
blah=seperatedList[i].split("\n");
name=blah[1];
department=blah[2];
if (blah[3].equals("null")) {
planning=null;
}else planning=blah[3];
if (blah[4].equals("null")) {
sport=null;
}else sport=blah[4];
if (blah[5].equals("null")) {
club=null;
}else club=blah[5];
if (blah[6].equals("null")) {
email=null;
}else email=blah[6];
if (blah[7].equals("null")) {
website=null;
}else website=blah[7];
teachers[i]=new Teacher(name, department, planning, sport, club, email, website);
}
return teachers;
}
我应该在哪里放置该文件,并且它仍然能够作为文件对象工作?
那么在哪里将“本地”,像在Android项目的文件夹? – werdho