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,
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
More Posts:
- Connect Azure AD (Active Directory) for PowerShell - Powershell
- How to get SharePoint Online user details from person or group column using REST API - SharePoint
- Enable Eclipse dark mode - Eclipse
- Java 20 (JDK) released and here is what is new and deprecated and deleted - Java
- Set Title to Android AlertDialog - Android
- Change label (text) color in tkinter - Python
- How to Change or Set a new Password for your Wi-Fi Router - HowTos
- JavaScript date in yyyy-MM-dd format - JavaScript