assert目录下文件的读取


普通的打开方式是:

InputStream inputStream = getAssets().open("test.xml");

带文件夹的:

getAssets().open("database/db.db");


在webview中的打开是:webView.loadUrl("file:///android_asset/test/index.html");

 

 

// bs = FileHelp.FileToXML("history.xml", getCon());// 直接读取根目录下的xml文件

 

 

bs = FileHelp.FileToXML(getCon().getResources().getAssets().open(
					"test/datasync.xml"), getCon());// 直接读取xml
 

 

public static String FileToXML(String filename, Context context) {
		InputStream ios = context.getClassLoader()
				.getResourceAsStream(filename);// 读取XML流
		BufferedReader in = new BufferedReader(new InputStreamReader(ios));
		StringBuffer buffer = new StringBuffer();
		String line = "";
		try {
			while ((line = in.readLine()) != null) {
				buffer.append(line);
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return buffer.toString();
	}
	
	public static String FileToXML(InputStream ios, Context context) {
		// InputStream ios = context.getClassLoader()
		// .getResourceAsStream(filename);// 读取XML流
		BufferedReader in = new BufferedReader(new InputStreamReader(ios));
		StringBuffer buffer = new StringBuffer();
		String line = "";
		try {
			while ((line = in.readLine()) != null) {
				buffer.append(line);
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		return buffer.toString();
	}
 

 

 

 

 

 

 

 

你可能感兴趣的:(assert)