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,
- Android Error Unexpected cast to Button: layout tag was FrameLayout
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK
- Parsing Data for android-21 failed unsupported major.minor version 51.0
- Android Studio Ctrl Shift o auto import not working
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android : How to make TextView Scrollable
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Integrating Android Facebook SDK 3.17.2 Tutorial
- Android R Cannot Be Resolved To A Variable
- Android : Exception raised during rendering: action_bar API 22
- How to take screenshot on Android
- Read Text file from SD Card : Android Programming
- How to make Android EditText not editable
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.
- The declared package does not match the expected package Eclipse
- Can't Run SDK Manager find_java.bat issue
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations
- Android Emulator Soft Back button action using Computer keyboard
- Multiline EditText in Android Example
- Use 5G Network on Android Emulator
- Make Android TextView Clickable like Buttons
- How to empty trash in Android Device
- Android : Execute some code after back button is pressed
- Disable Fading Edges Scroll Effect Android Views
- How To Disable Landscape Mode in Android Application
More Posts:
- M365 service Europe outage - AADSTS90033 A transient error has occurred. Please try again. - Microsoft
- Error code 0xCAA82EE2: Something went wrong (request timed out) [Microsoft] - Microsoft
- Make Notepad++ the default App for .txt file extensions - NotepadPlusPlus
- How to find files taking up space on your Mac - MacOS
- How to fix: Please check your network connection (Retry) - HowTos
- [Android Studio] Button on click example - Android-Studio
- Make Android View Scrollable both Horizontally and Vertically - Android
- Java JDBC Example with Oracle Database Driver Connection - Java