In Android webview, you could pass something like this file:///android_asset/myfile.txt or this http://www.mysite.com/t.html and it will get it without a problem. Now if I tried the first url with the file prefix in a reader “FileReader” it will throw an exception that File not found although in WebView it work with no problem (why?)
What I want is to create a function that could take a file or http url and get the content html using the full path “file:/// …” how could I do this without facing the file not found exception ?
Because “File Reader” does not have an asset named
/myfile.txt, presumably. “File Reader” is somebody else’s program, not yours, sofile:///android_asset/myfile.txtrefers to an asset in that other program, not yours.Have an asset named
/myfile.txtin your app.I have not tried using standard Java I/O (e.g.,
Fileobjects) to readfile:///android_assetpaths. That might work. If not, usestartsWith()to determine if the string begins withfile:///android_asset— if it does, trim that off and use the rest withAssetManagerto read the asset.