Android读取assests目录下文件

随手记录下来,以后直接用,不用再搜了

	private void readFromAssets(String fileName){
		try {
			InputStream in = getAssets().open(fileName);
			readTextFile(in);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	private String readTextFile(InputStream inputStream) {

		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		byte buf[] = new byte[1024];
		int len;
		try {
			while ((len = inputStream.read(buf)) != -1) {
				outputStream.write(buf, 0, len);
			}
			outputStream.close();
			inputStream.close();
		} catch (IOException e) {
		}
		return outputStream.toString();
	}


你可能感兴趣的:(Android,Java)