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. Android bitmap allocation weirdness

I'm having some trouble understanding why this code

public class BitmapAllocTest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        byte[] b = new byte[20 * 1000 * 1000];
        b = null;
        Bitmap.createBitmap(2500, 2000, Bitmap.Config.ARGB_8888);
    }
}
throws an OutOfMemory exception on a device with a 24mb heap limit. If
I comment out either of the allocations it runs fine. I was under the
impression that the java vm would try to garbage collect before
throwing OutOfMemory exceptions.

I suspect it having to do with android allocating the bitmaps on the
native heap.

PS. This is a clone from my stackoverflow question
http://stackoverflow.com/questions/3546635/android-bitmap-allocation-weirdness
which hasn't gotten a satisfactory answer yet.

-- 

2. Sharing code between apps as in Eclipse

I have ten, possibly more, apps I'm developing that all share logic.
50-75% of the logic is the same - perfect for some time of library or
code sharing. However, after reading the posts here and trying to
share code in Eclipse, I'm not sure that's going to work. I tried
going to project -> properties -> build path -> link source and adding
the src and gen folders of the project with the shared code and then
importing the classes I need. That seems to work in the IDE, but gives
an error during runtime: class not found. This seems to be a common
error for people attempting this.

I am slowly deciding that shared code is not the best approach in this
scenario. Android doesn't seem to work well with this type of code
sharing. For one thing resources are not packed in libraries, but
references (R.whatever) must exist so as not to create errors. This
can be designed around, but the effort and headache is probably worse
than simply creating multiple copies.

What are you thoughts on the topic?  My experience seems typical,
based on what I've read. Is it? Have you experienced success or
failure with sharing code and/or custom libraries?  Am I off-base in
thinking that multiple code copies will be smoother sailing than
fighting the shared code approach?

-- 

3. copybit format conversion issue, for help

4. Unsuccessful install of successful built apk

5. Porting Information

6. JDOM in Android 2.1 or earlier

7. getPreviewSize() bad result on Froyo emulator