我正在从 SD 卡读取文本文件。如果文件大小很小,我的代码可以工作,但是当文件大于 4 或 5 mb 时,它会给我一个错误。
这是我使用的代码:
File myFile = new File(""+listAllSdCardFile.get(filePostion));
BufferedReader br1 = new BufferedReader( new FileReader( myFile ) );
StringBuffer text = new StringBuffer();
for(String line; (line=br1.readLine())!=null;)
{
text.append( line );
}
line=text.toString();
这是我得到的错误:
02-05 07:12:55.184: E/AndroidRuntime(778): FATAL EXCEPTION: Background
02-05 07:12:55.184: E/AndroidRuntime(778): java.lang.OutOfMemoryError
02-05 07:12:55.184: E/AndroidRuntime(778): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
02-05 07:12:55.184: E/AndroidRuntime(778): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:157)
02-05 07:12:55.184: E/AndroidRuntime(778): at java.lang.StringBuffer.append(StringBuffer.java:215)
02-05 07:12:55.184: E/AndroidRuntime(778): at com.reader.fastreader.TextReader.StringSpilitFunction(TextReader.java:344)
02-05 07:12:55.184: E/AndroidRuntime(778): at com.reader.fastreader.TextReader$3$1$1.run(TextReader.java:134)
02-05 07:12:55.184: E/AndroidRuntime(778): at java.lang.Thread.run(Thread.java:1096)
02-05 07:12:55.784: E/WindowManager(778): Activity com.reader.fastreader.TextReader has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f74708 that was originally added here
02-05 07:12:55.784: E/WindowManager(778): android.view.WindowLeaked: Activity com.reader.fastreader.TextReader has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f74708 that was originally added here
02-05 07:12:55.784: E/WindowManager(778): at android.view.ViewRoot.<init>(ViewRoot.java:247)
02-05 07:12:55.784: E/WindowManager(778): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
02-05 07:12:55.784: E/WindowManager(778): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
02-05 07:12:55.784: E/WindowManager(778): at android.view.Window$LocalWindowManager.addView(Window.java:424)
02-05 07:12:55.784: E/WindowManager(778): at android.app.Dialog.show(Dialog.java:241)
02-05 07:12:55.784: E/WindowManager(778): at com.reader.fastreader.TextReader$3$1.onItemClick(TextReader.java:140)
02-05 07:12:55.784: E/WindowManager(778): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-05 07:12:55.784: E/WindowManager(778): at android.widget.ListView.performItemClick(ListView.java:3382)
02-05 07:12:55.784: E/WindowManager(778): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
02-05 07:12:55.784: E/WindowManager(778): at android.os.Handler.handleCallback(Handler.java:587)
02-05 07:12:55.784: E/WindowManager(778): at android.os.Handler.dispatchMessage(Handler.java:92)
02-05 07:12:55.784: E/WindowManager(778): at android.os.Looper.loop(Looper.java:123)
02-05 07:12:55.784: E/WindowManager(778): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 07:12:55.784: E/WindowManager(778): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 07:12:55.784: E/WindowManager(778): at java.lang.reflect.Method.invoke(Method.java:521)
02-05 07:12:55.784: E/WindowManager(778): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 07:12:55.784: E/WindowManager(778): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 07:12:55.784: E/WindowManager(778): at dalvik.system.NativeStart.main(Native Method)
我的代码有什么问题?