04-04 23:22:21.869: E/AndroidRuntime(7417): FATAL EXCEPTION: main
04-04 23:22:21.869: E/AndroidRuntime(7417): java.lang.IllegalStateException: Could not execute method of the activity
04-04 23:22:21.869: E/AndroidRuntime(7417): Caused by: java.lang.reflect.InvocationTargetException
04-04 23:22:21.869: E/AndroidRuntime(7417): Caused by: java.lang.IllegalArgumentException: File /Dir/data.txt contains a path separator
04-04 23:22:21.869: E/AndroidRuntime(7417): at android.app.ContextImpl.makeFilename(ContextImpl.java:1674)
04-04 23:22:21.869: E/AndroidRuntime(7417): at android.app.ContextImpl.openFileInput(ContextImpl.java:412)
04-04 23:22:21.869: E/AndroidRuntime(7417): at android.content.ContextWrapper.openFileInput(ContextWrapper.java:152)
04-04 23:22:21.869: E/AndroidRuntime(7417): at com.code2care.readtextfile.MainActivity.getTextFileData(MainActivity.java:44)
04-04 23:22:21.869: E/AndroidRuntime(7417): at com.code2care.readtextfile.MainActivity.getTextFile(MainActivity.java:29)
04-04 23:22:21.869: E/AndroidRuntime(7417): ... 14 more
I got the above error message while trying to access the file from Internal Storage using openFileInput("/Dir/data.txt") method with subdirectory Dir. The reason is that you cannot access subdirectories using this method, just try something like,
FileInputStream fIS = new FileInputStream (new File("/Dir/data.txt"));
Code Snippet:try {
FileInputStream fIS = new FileInputStream (new File(fileName));
InputStreamReader isr = new InputStreamReader(fIS, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
text.append(line + '\n');
}
br.close();
fIS.close();
} catch (IOException e) {
Log.e("C2c", "Error occured while reading text file!!");
}
More Posts related to Android,
- Change Android Toast background color
- Maven : java.lang.ClassNotFoundException: Xmx512m
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Android Alert Dialog with Checkboxes example
- Android Error Generating Final Archive - Debug Certificate Expired
- How to add Newline to text in Android TextView
- Read Text file from SD Card : Android Programming
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- ActivityManager Warning: Activity not started, its current task has been brought to the front
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Android Developers Bluetooth Tutorial
- java.lang.ClassNotFoundException android.support.v7.widget.Toolbar [Fix]
- Android: Save Data in local Db using Android Room
- Channel 50 SMSes received every few minutes Android Phones
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Changing Android Intent Tittle using java code
- Android : No Launcher activity found! Error
- How to change TextView or EditText Text Color on Focus and on Press
- How to display Toast on Button Click : Android
- Android : Execute some code after back button is pressed
- Stop android adb service from command prompt or terminal
- [Soluiton] You already have the latest version of Android Studio installed
- Create Custom Android AlertDialog
- Android R Cannot Be Resolved To A Variable
- How to make Android EditText not editable
More Posts:
- Microsoft 365 Excel - PRO TIP Discover insights quickly with Power BI, which is already included in your Microsoft services, See it in action - Microsoft
- MacoOS - xyz is an app downloaded from the internet. Are you sure you want to open it? Alert - MacOS
- zsh: exec format error eclipse M1 Mac - zsh
- Eclipse version 32-bit or 64-bit check on macOS - Eclipse
- Change Mouse Scrolling in Mac OS X - Mac-OS-X
- How to remove or uninstall Java from Ubuntu using apt-get - Linux
- Be right back We’re making updates to the Apple Store. Check back soon. - Apple
- Execute .bin and .run file Ubuntu Linux - Linux