开发者

90112 bytes limit for data files?

开发者 https://www.devze.com 2023-01-19 16:17 出处:网络
I create data file in android for my application in the app\'s data directory. The write is successful with no exceptions but file contents are not complete. It truncates at 90112 bytes. Any idea what

I create data file in android for my application in the app's data directory. The write is successful with no exceptions but file contents are not complete. It truncates at 90112 bytes. Any idea what is going on ? Is there a limit ?

Here is the snippet


try {
            fos = parentActivity.openFileOutput(mmCacheFName,
                    Context.MODE_PRIVATE | Context.MODE_APPEND);
            OutputStreamWriter osw = new OutputStreamWriter(fos);
            BufferedWriter bosw = new BufferedWriter(osw);
            int indx = lastIndx - 10;
            while (indx >= 0) {
                IEventHolder ev = de开发者_开发知识库ltaList.get(indx);
                bosw.write(ev.getRawData() + "\n");
                indx--;
            }
            osw.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Throwable t) {
                t.printStackTrace() 
        } finally {
            try {
                if (fos != null)
                    fos.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }


There might be lots of reasons. If you send your code, it's easier to track the problem. But you could check:

  1. you have closed your Stream when writing to the file (It is recommended that you do it in a finally block) like this:

    try{ .... write the data to the file with some outputStream }finally{ outputStream.close(); }

  2. If you want to read the data before closing the stream, make sure your output-stream does not buffer the output. if it does, before reading the data, flush the output to the file:

    outputStream.flush();

  3. Check for any exception that might be caught, but not logged, some code like this:

    try{ ... }catch(IOException ex){ // here must log the exception. }

}


Thanks for your responses. I figured out what the issue was, I should be flushing and closing the BufferedWriter instead of OutputStreamWriter. Thanks again

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号