Try this :
I assume your text file is on sd card
//Find the directory for the SD Card using the API //*Don't* hardcode "/sdcard" File sdcard = Environment.getExternalStorageDirectory(); //Get the text file File file = new File(sdcard,"file.txt"); //Read text from file StringBuilder text = new StringBuilder(); try { BufferedReader br = new BufferedReader(new FileReader(file)); String line; while ((line = br.readLine()) != null) { text.append(line); text.append('\n'); } br.close(); } catch (IOException e) { //You'll need to add proper error handling here } //Find the view by its id TextView tv = (TextView)findViewById(R.id.text_view); //Set the text tv.setText(text.toString());
following links can also help you :
How can I read a text file from the SD card in Android?
How to read text file in Android?
Android read text raw resource file
Related Posts:
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- What is a StackOverflowError?
- What is the proper way to handle a NumberFormatException when it is expected?
- Exception in thread “main” java.util.NoSuchElementException
- Converting double to string
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- Error parsing data org.json.JSONException: Value
- What does “|=” mean? (pipe equal operator)
- JavaFX – Exception in Application start method?
- What is a StringIndexOutOfBoundsException? How can I fix it?
- How do popBackStack() and replace() operations differ?
- Given final block not properly padded
- What is an AssertionError? In which case should I throw it from my own code?
- EOFException – how to handle?
- @ converted to %40 in HTTPPost request
- Unfortunately MyApp has stopped. How can I solve this?
- Can I catch multiple Java exceptions in the same catch clause?
- How to convert any Object to String?
- Unfortunately MyApp has stopped. How can I solve this?
- Exception in thread “main” java.util.NoSuchElementException: No line found
- “NoClassDefFoundError: Could not initialize class” error
- unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown
- Exception in thread “main” java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)
- “NoClassDefFoundError: Could not initialize class” error
- “NoClassDefFoundError: Could not initialize class” error
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- Attempt to invoke virtual method ‘…’ on a null object reference
- Why do I get “Exception; must be caught or declared to be thrown” when I try to compile my Java code?
- Getting java.net.SocketTimeoutException: Connection timed out in android
- This view is not constrained
- How to use VisibleForTesting for pure JUnit tests
- How to parse JSON boolean value?
- ADK vs JDK vs SDK difference?
- Causes of getting a java.lang.VerifyError
- How to create a custom exception type in Java?
- Android java.lang.IllegalStateException: Could not execute method of the activity
- How can I fix ‘android.os.NetworkOnMainThreadException’?
- Default keystore file does not exist?
- Execution Failed for task :app:compileDebugJavaWithJavac in Android Studio
- How to print to the console in Android Studio?
- The activity must be exported or contain an intent-filter
- align text center with android
- Pause the timer and then continue it
- Variable is accessed within inner class. Needs to be declared final
- Extending from two classes
- ‘Source code does not match the bytecode’ when debugging on a device
- Android – SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
- This Activity already has an action bar supplied by the window decor?
- Cannot resolve symbol “Intent”
- Eclipse error, “The selection cannot be launched, and there are no recent launches”
- RecyclerView onClick
- Exception in thread “main” java.lang.ArithmeticException: / by zero
- Display Animated GIF
- Java can’t find file when running through Eclipse
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- Getting warning “NDK is missing a ‘platforms” directory.’ with no NDK
- Converting a string to an integer on Android
- The specified child already has a parent. You must call removeView() on the child’s parent first (Android)
- exposed beyond app through ClipData.Item.getUri
- method does not override method in its superclass
- How to create JSON Object using String?
- Why doesn’t RecyclerView have onItemClickListener()?
- StringIndexOutOfBoundsException String index out of range: 0
- How to pass an object from one activity to another on Android
- “Field can be converted to a local variable” message appearing when setting Android ActionBar colour
- Google firebase check if child exists
- How to Get JSON Array Within JSON Object?
- Android For loop
- Cannot resolve symbol ‘button’ -Android Studio
- Aspect Ratio with 800×480
- java.lang.ClassNotFoundException:com.mysql.jdbc.Driver [duplicate]
- How to “wait” a Thread in Android
- Why is a ConcurrentModificationException thrown and how to debug it
- E/AndroidRuntime﹕ FATAL EXCEPTION: main
- Android Color Picker
- Android Emulator: Unfortunately App has stopped
- Throwing multiple exceptions in Java
- JAVA_HOME is set to an invalid directory:
- why android studio show error of “Missing constraints in constraintlayout”?
- java.lang.ArrayIndexOutOfBoundsException: 0
- Detecting a long press with Android
- void is an invalid type for this variable
- syntax error: insert } to complete ClassBody
- java.lang.ClassNotFoundException: org.postgresql.Driver, Android
- Eclipse: JVM terminated. Exit code=2
- How can I wait for 10 second without locking application UI in android [duplicate]
- Getting a “no interface expected here” when I try to subclass ServiceConnection [duplicate]
- Official reasons for “Software caused connection abort: socket write error”
- Decompile .smali files on an APK [duplicate]
- Unable to resolve host “
” No address associated with host name - android.content.res.Resources$NotFoundException: String resource ID #0x0
- How to set menu to Toolbar in Android
- How fix Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
- Android: how to create Switch case from this?
- Exception is never thrown in body of corresponding try statement
- method does not override or implement a method from a supertype – for Override
- set background color: Android
- How can I catch all the exceptions that will be thrown through reading and writing a file?
- set background color: Android
- No content to map due to end-of-input jackson parser