------ Solution ---------------------------------------- ----
look at what went wrong
------ Solution --------------------------- -----------------
read this section of the code sent to see
------ For reference only ---------- -----------------------------
you read this android 100M. Little big ah. Memory is enough of it . You are using a virtual machine or fax machine ?
------ For reference only ---------------------------------- -----
recommended to use a small bit of the file to test . If you can, come back to look at this problem 100M , there may be insufficient memory , ran directly to rout out
------ For reference only ----------------- ----------------------
I was playing for example , the file is not so big , I was afraid that people say all the file is read into memory , and then look for where it is needed . Files also a few M
------ For reference only --------------------------------- ------
so much red , I do not understand is, please help us to see
10-21 17:47:41.976: E / AndroidRuntime (12965): FATAL EXCEPTION: main
10-21 17:47:41.976: E / AndroidRuntime (12965): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.TianYe.ZhiNengJiaJu / com . TianYe.ZhiNengJiaJu.MainActivity}: java.lang.IndexOutOfBoundsException
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 1728)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java: 1747)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread.access $ 1500 (ActivityThread.java: 155)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread $ H.handleMessage (ActivityThread.java: 993)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.os.Handler.dispatchMessage (Handler.java: 130)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.os.Looper.loop (SourceFile: 351)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread.main (ActivityThread.java: 3814)
10-21 17:47:41.976: E / AndroidRuntime (12965): at java.lang.reflect.Method.invokeNative (Native Method)
10-21 17:47:41.976: E / AndroidRuntime (12965): at java.lang.reflect.Method.invoke (Method.java: 538)
10-21 17:47:41.976: E / AndroidRuntime (12965): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 901)
10-21 17:47:41.976: E / AndroidRuntime (12965): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 659)
10-21 17:47:41.976: E / AndroidRuntime (12965): at dalvik.system.NativeStart.main (Native Method)
10-21 17:47:41.976: E / AndroidRuntime (12965): Caused by: java.lang.IndexOutOfBoundsException
10-21 17:47:41.976: E / AndroidRuntime (12965): at java.io.FileInputStream.read (FileInputStream.java: 311)
10-21 17:47:41.976: E / AndroidRuntime (12965): at com.TianYe.ZhiNengJiaJu.MainActivity.onCreate (MainActivity.java: 78)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java: 1082)
10-21 17:47:41.976: E / AndroidRuntime (12965): at android.app.ActivityThread.performLaunchActivity (ActivityThread.java: 1692)
10-21 17:47:41.976: E / AndroidRuntime (12965): ... 11 more
------ For reference only ---------------------------------- -----
but as long as the . read (buffer, byteOffset, byteCount) function replaced . read (buffer), no problem
------ For reference only - -------------------------------------
SetFileRead is when the program starts it has been created the
public static String ReadSetFile(int Offset ,int count)
{
byte buf[]=new byte[count];
try
{
SetFileRead.read(buf, Offset, count);
//改成 SetFileRead.read(buf);就不出错
return buf.toString();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
------ For reference only ----------------------------------- ----
just learning java soon, I do not know java inside manipulate files there's nothing like the current position inside the c language concepts , if this concept can also be solved , first the current position is set to Offset, go size count bytes , but I check in online for a long time , has not found this thing , do java inside can only read from the file stream ?
------ For reference only -------------------------------------- -
com.TianYe.ZhiNengJiaJu / com.TianYe.ZhiNengJiaJu.MainActivity}: java.lang.IndexOutOfBoundsException
Here is an array out of bounds .
------ For reference only -------------------------------------- -
first skip it.
skip
public long skip (long n)
throws IOException
skipped from the input stream and discards n bytes of data .
For various reasons , skip number of bytes skipped the final approach and probably fewer , perhaps even to zero. If n is negative , then throws IOException, even skip method of InputStream superclass in this case did not do anything. Returns the actual number of bytes skipped .
This method may be more bytes to skip the remaining bytes in the underlying file . This does not generate an exception , and the number of bytes skipped may include underlying file EOF ( end of file ) after some number of bytes . If you try to read the stream after the end of the jump , it will return -1 indicates end of the file .
coverage :
class InputStream skip
parameters:
n - the number of bytes to be skipped .
Returns:
actual number of bytes skipped .
Throws:
IOException - If n is negative, or an I / O error .
------ For reference only ---------------------------------- -----
indeed array bounds , and had read (buf, Offset, count) in the offset parameter refers buf offset instead of a file offset volume . It can only use upstairs , just read once, the next read will write pointer ( current position ) set to the beginning of the file , go calculate how much should be offset , only to find a function with the mark .
没有评论:
发表评论