My code is following::
Scanner sc = null;
try {
sc = new Scanner(new File("assets/mainmenu/readSourceFile.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println(e1.toString());
e1.printStackTrace();
}
Then, logcat show exception java.io.FileNotFoundException
How can I find my file? I tried
sc = new Scanner(new File("mainmenu/readSourceFile.txt"));
However, it's still throw FilenotFoundException
My file is in folder assets/mainmenu/readSourceFile.txt
and I've try this::
private InputStream is;
try {
is = this.getResources().getAssets().open("mainmenu/readSourceFile.txt");
} catch (IOException e) {
e.toString();
}
I use getAssets to access assets file in android. However, how can I suppose to read text file if I use InputStream
android.graphics.Path. The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves. It can be drawn with canvas.
You try this...Hope it will work
sc = new Scanner(new File("file:///android_asset/mainmenu/readSourceFile.txt");
Edit try this
AssetFileDescriptor descriptor = getAssets().openFd("mainmenu/readSourceFile.txt");
FileReader reader = new FileReader(descriptor.getFileDescriptor());
Copied from here Asset folder path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With