below is logcat result which shows out of memory problem.
it may be involved with too big byte[] array.
04-17 22:21:38.773: W/dalvikvm(4963): threadid=1: thread exiting with uncaught exception (group=0x40a4d1f8)
04-17 22:21:38.781: E/AndroidRuntime(4963): FATAL EXCEPTION: main
04-17 22:21:38.781: E/AndroidRuntime(4963): java.lang.OutOfMemoryError
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.nio.CharBuffer.put(CharBuffer.java:509)
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.nio.charset.CharsetDecoder.allocateMore(CharsetDecoder.java:238)
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:195)
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.nio.charset.Charset.decode(Charset.java:487)
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.lang.String.(String.java:174)
04-17 22:21:38.781: E/AndroidRuntime(4963): at java.lang.String.(String.java:141)
04-17 22:21:38.781: E/AndroidRuntime(4963): at exam.militarymgrs.Draw_LOS.readFile(Draw_LOS.java:182)
Draw_LOS.java:182 is as follows.
(String s = new String(dat);)
——-Source code————–
public static ArrayList<String> readFile(String fileName) {
//map data access
String sdPath;
sdPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
File file = new File(sdPath+fileName);
//String[] k = new String[1440000];
//String line = "";
ArrayList<String> data = new ArrayList<String>();//consider using ArrayList<int>
try {
FileInputStream fis = new FileInputStream(file);
byte[] dat = new byte[fis.available()];
String s = new String(dat);
String[] k = s.split("[\\r\\n]+");
while(fis.read(dat) != -1) {;}
fis.close();
}
catch(FileNotFoundException fN) {
fN.printStackTrace();
}
catch(IOException e) {
System.out.println(e);
}
return data;
}
A file which should be loaded is as follows
12
32
43
…
How can I read the data file without Out of Memory with fileStream??
try to use this: