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",
Context.MODE_PRIVATE);
cachedImage.compress(CompressFormat.JPEG, 75, Os);
Os.close();


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);
Is.close();


**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)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training...At Your Office:  http://commonsware.com/training 

--


Sponsored Links


Other Threads

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

Hi,

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:

http://www.freesound.org/download/23246/23246_acclivity_GullsByTheSea.mp3

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;

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

                conn = (HttpURLConnection) sourceURL.openConnection();
                conn.connect();

                inStream = conn.getInputStream();

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

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

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

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

                readBytes = inStream.read(bytes, 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);

                        try
                        {
                                wait(100);
                        }
                        catch(InterruptedException ie){}

                        readBytes = inStream.read(bytes, 0, 1024);
                }
        }
        catch(Exception e)
        {
                Log.d(TAG, "Run exception: " + e.toString());
        }
        finally
        {
                Log.d(TAG, "Finally");
                try
                {
                        inStream.close();
                        outStream.close();
                }
                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?