[java]apk中assets檔案讀取
阿新 • • 發佈:2019-02-11
一、讀取整個檔案內容
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();
}