private file last modified date

by Dson » Sun, 01 Aug 2010 13:06:35 GMT

Sponsored Links
 Hi Guys,

 I am trying to get the last modified date of an internal file and it
always returns me 0 although I could read the file properly. Can you
please let me know if I am doing anything wrong...

Creating a file...

FileOutputStream Os = activity.openFileOutput("file1.jpg",
cachedImage.compress(CompressFormat.JPEG, 75, Os);

Reading the file...
long mod_time = 0;
File file = new File("file1".jpg");
mod_time = file.lastModified();
FileInputStream Is = activity.openFileInput("file1.jpg");
cachedImage = BitmapFactory.decodeStream(Is);

**mod_time is always zero!!!!**


private file last modified date

by Mark Murphy » Sun, 01 Aug 2010 14:53:33 GMT


That is because you are looking at the wrong file. Use new
File(getFilesDir(), "file1.jpg") to get at the same file that you use
with openFileInput()/openFileOutput().

Mark Murphy (a Commons Guy)  |  | 

Android Training...At Your Office: 


Sponsored Links

Other Threads

1. How to set the width and height of an ImageView programmically?


Can you please tell me how can i set the width and height of an
ImageView programmically in java code (not layout xml file)?
I tried setMinimumWidth/setMinimumHeight, but that does not work. I
have looked at the view in HierarchyView, it still said the width to
be 80 and height to be 100. And that is not the value I set.

Thank you.


2. MP3 download problem

I'm trying to download files such as:

to the SDCARD of my t-mobile G1.

I can only download about 2^16 ~ (16384 bytes) before my input stream
read returns -1.

This wouldn't be a problem if the connection object could retrieve the
content's length, so that I would keep trying the read when the total
bytes have not yet been downloaded ... but the connection object
always returns -1 for the content length.

Any thoughts or tips...

My code is below:

private synchronized void download()
        HttpURLConnection conn = null;
        InputStream inStream = null;
        FileOutputStream outStream = null;

                //Where the file comes from
                URL sourceURL = new URL(m_url);

                conn = (HttpURLConnection) sourceURL.openConnection();

                inStream = conn.getInputStream();

                Log.d(TAG, "content length = " + conn.getContentLength()); // 
returns -1

                // Where the file is going to go
                outStream = new FileOutputStream("/sdcard/Music/" + 

                //a read buffer
                byte[] bytes = new byte[1024];

                //read the first chunk
                int readBytes = 0;
                int total = 0;

                readBytes =, 0, 1024);

                Log.d(TAG, "readBytes = " + readBytes);

                while (readBytes > 0)
                        total += readBytes;

                        //Write the buffered chunk to the file
                        outStream.write(bytes, 0, readBytes);

                        Log.d(TAG, "total = " + total);

                        catch(InterruptedException ie){}

                        readBytes =, 0, 1024);
        catch(Exception e)
                Log.d(TAG, "Run exception: " + e.toString());
                Log.d(TAG, "Finally");
                catch (IOException e){}

3. What UI Elements in AppWidget?

4. Null pointer on setBackgroundResource

5. How to draw a rectangle on screen using layout.xml file

6. How Delete SMS from inbox programmatically OR discard it before received in inbox

7. Why does Android Market give me this error?