一、读取整个文件内容
InputStream is = getClass().getResourceAsStream("/assets/xxx.txt");
int length = is.available();
byte buffer = new byte[length];
is.read(buffer);
is.close();
二、逐行读取文件内容
BufferedReader br = null;
String[] stringArray =new String[6];
ArrayList<Point> P20array= new ArrayList<Point>();
int x,y;
try {
br = new BufferedReader(new InputStreamReader( getClass().getResourceAsStream("/assets/xxx.txt")));
for (String line = br.readLine(); line != null; line = br.readLine()) {
stringArray=line.split(",");
x = Integer.parseInt(stringArray[0]);
y = Integer.parseInt(stringArray[1]);
Point p20Point= new Point();
p20Point.x = (int)x;
p20Point.y = (int)y;
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}