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. Strange exception that doesn't cause any harm apparently!

I have a ListActivity class that has a list of items. I am using the
List14 (http://developer.android.com/guide/samples/ApiDemos/src/com/
example/android/apis/view/List14.html) sample from android to build
this ListActivity with icons+text for each row. Clicking each of these
items would launch an Activity.

Whenever my ListActivity starts, I get the below strange exceptions in
logcat, but it seems to cause no harm, as the application works fine.
But I'm curious as to what could be causing it. Any ideas?

D/skia    (29776): ---- read threw an exception
W/System.err(29776): java.io.IOException: Is a directory
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.readImp
l(Native Method)
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.read(OS
FileSystem.java:154)
W/System.err(29776):    at java.io.FileInputStream.read
(FileInputStream.java:333
)
W/System.err(29776):    at java.io.BufferedInputStream.fillbuf
(BufferedInputStre
am.java:200)
W/System.err(29776):    at java.io.BufferedInputStream.read
(BufferedInputStream.
java:350)
W/System.err(29776):    at
android.graphics.BitmapFactory.nativeDecodeStream(Nat
ive Method)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeStream
(BitmapFac
tory.java:451)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:270)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:295)
W/System.err(29776):    at org.examples.listexample
$EfficientAdapter.getView(
FitDeck.java:105)
W/System.err(29776):    at android.widget.AbsListView.obtainView
(AbsListView.jav
a:1255)
W/System.err(29776):    at android.widget.ListView.makeAndAddView
(ListView.java:
1658)
W/System.err(29776):    at android.widget.ListView.fillDown
(ListView.java:637)
W/System.err(29776):    at android.widget.ListView.fillSpecific
(ListView.java:12
24)
W/System.err(29776):    at android.widget.ListView.layoutChildren
(ListView.java:
1494)
W/System.err(29776):    at android.widget.AbsListView.onLayout
(AbsListView.java:
1112)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.LinearLayout.setChildFrame
(LinearLayou
t.java:1119)
W/System.err(29776):    at android.widget.LinearLayout.layoutVertical
(LinearLayo
ut.java:998)
W/System.err(29776):    at android.widget.LinearLayout.onLayout
(LinearLayout.jav
a:918)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.view.ViewRoot.performTraversals
(ViewRoot.java
:979)
W/System.err(29776):    at android.view.ViewRoot.handleMessage
(ViewRoot.java:161
3)
W/System.err(29776):    at android.os.Handler.dispatchMessage
(Handler.java:99)
W/System.err(29776):    at android.os.Looper.loop(Looper.java:123)
W/System.err(29776):    at android.app.ActivityThread.main
(ActivityThread.java:4
203)
W/System.err(29776):    at java.lang.reflect.Method.invokeNative
(Native Method)
W/System.err(29776):    at java.lang.reflect.Method.invoke(Method.java:
521)
W/System.err(29776):    at com.android.internal.os.ZygoteInit
$MethodAndArgsCalle
r.run(ZygoteInit.java:791)
W/System.err(29776):    at com.android.internal.os.ZygoteInit.main
(ZygoteInit.ja
va:549)
W/System.err(29776):    at dalvik.system.NativeStart.main(Native
Method)
D/skia    (29776): ---- read threw an exception
W/System.err(29776): java.io.IOException: Is a directory
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.readImp
l(Native Method)
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.read(OS
FileSystem.java:154)
W/System.err(29776):    at java.io.FileInputStream.read
(FileInputStream.java:333
)
W/System.err(29776):    at java.io.BufferedInputStream.fillbuf
(BufferedInputStre
am.java:200)
W/System.err(29776):    at java.io.BufferedInputStream.read
(BufferedInputStream.
java:350)
W/System.err(29776):    at
android.graphics.BitmapFactory.nativeDecodeStream(Nat
ive Method)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeStream
(BitmapFac
tory.java:451)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:270)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:295)
W/System.err(29776):    at org.examples.listexample
$EfficientAdapter.getView(
FitDeck.java:105)
W/System.err(29776):    at android.widget.AbsListView.obtainView
(AbsListView.jav
a:1255)
W/System.err(29776):    at android.widget.ListView.makeAndAddView
(ListView.java:
1658)
W/System.err(29776):    at android.widget.ListView.fillDown
(ListView.java:637)
W/System.err(29776):    at android.widget.ListView.fillSpecific
(ListView.java:12
24)
W/System.err(29776):    at android.widget.ListView.layoutChildren
(ListView.java:
1494)
W/System.err(29776):    at android.widget.AbsListView.onLayout
(AbsListView.java:
1112)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.LinearLayout.setChildFrame
(LinearLayou
t.java:1119)
W/System.err(29776):    at android.widget.LinearLayout.layoutVertical
(LinearLayo
ut.java:998)
W/System.err(29776):    at android.widget.LinearLayout.onLayout
(LinearLayout.jav
a:918)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.view.ViewRoot.performTraversals
(ViewRoot.java
:979)
W/System.err(29776):    at android.view.ViewRoot.handleMessage
(ViewRoot.java:161
3)
W/System.err(29776):    at android.os.Handler.dispatchMessage
(Handler.java:99)
W/System.err(29776):    at android.os.Looper.loop(Looper.java:123)
W/System.err(29776):    at android.app.ActivityThread.main
(ActivityThread.java:4
203)
W/System.err(29776):    at java.lang.reflect.Method.invokeNative
(Native Method)
W/System.err(29776):    at java.lang.reflect.Method.invoke(Method.java:
521)
W/System.err(29776):    at com.android.internal.os.ZygoteInit
$MethodAndArgsCalle
r.run(ZygoteInit.java:791)
W/System.err(29776):    at com.android.internal.os.ZygoteInit.main
(ZygoteInit.ja
va:549)
W/System.err(29776):    at dalvik.system.NativeStart.main(Native
Method)
D/skia    (29776): ---- read threw an exception
W/System.err(29776): java.io.IOException: Is a directory
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.readImp
l(Native Method)
W/System.err(29776):    at
org.apache.harmony.luni.platform.OSFileSystem.read(OS
FileSystem.java:154)
W/System.err(29776):    at java.io.FileInputStream.read
(FileInputStream.java:333
)
W/System.err(29776):    at java.io.BufferedInputStream.fillbuf
(BufferedInputStre
am.java:200)
W/System.err(29776):    at java.io.BufferedInputStream.read
(BufferedInputStream.
java:350)
W/System.err(29776):    at
android.graphics.BitmapFactory.nativeDecodeStream(Nat
ive Method)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeStream
(BitmapFac
tory.java:451)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:270)
W/System.err(29776):    at android.graphics.BitmapFactory.decodeFile
(BitmapFacto
ry.java:295)
W/System.err(29776):    at org.examples.listexample
$EfficientAdapter.getView(
FitDeck.java:105)
W/System.err(29776):    at android.widget.AbsListView.obtainView
(AbsListView.jav
a:1255)
W/System.err(29776):    at android.widget.ListView.makeAndAddView
(ListView.java:
1658)
W/System.err(29776):    at android.widget.ListView.fillDown
(ListView.java:637)
W/System.err(29776):    at android.widget.ListView.fillSpecific
(ListView.java:12
24)
W/System.err(29776):    at android.widget.ListView.layoutChildren
(ListView.java:
1494)
W/System.err(29776):    at android.widget.AbsListView.onLayout
(AbsListView.java:
1112)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.LinearLayout.setChildFrame
(LinearLayou
t.java:1119)
W/System.err(29776):    at android.widget.LinearLayout.layoutVertical
(LinearLayo
ut.java:998)
W/System.err(29776):    at android.widget.LinearLayout.onLayout
(LinearLayout.jav
a:918)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.widget.FrameLayout.onLayout
(FrameLayout.java:
333)
W/System.err(29776):    at android.view.View.layout(View.java:6569)
W/System.err(29776):    at android.view.ViewRoot.performTraversals
(ViewRoot.java
:979)
W/System.err(29776):    at android.view.ViewRoot.handleMessage
(ViewRoot.java:161
3)
W/System.err(29776):    at android.os.Handler.dispatchMessage
(Handler.java:99)
W/System.err(29776):    at android.os.Looper.loop(Looper.java:123)
W/System.err(29776):    at android.app.ActivityThread.main
(ActivityThread.java:4
203)
W/System.err(29776):    at java.lang.reflect.Method.invokeNative
(Native Method)
W/System.err(29776):    at java.lang.reflect.Method.invoke(Method.java:
521)
W/System.err(29776):    at com.android.internal.os.ZygoteInit
$MethodAndArgsCalle
r.run(ZygoteInit.java:791)
W/System.err(29776):    at com.android.internal.os.ZygoteInit.main
(ZygoteInit.ja
va:549)
W/System.err(29776):    at dalvik.system.NativeStart.main(Native
Method)

-- 

2. Join over 3,000 - The Android Developer Group on Linkedin

Join over 3,000 others and discuss all things Android at:
http://www.linkedin.com/groupRegistration?gid=86481

Join the Android Developer group on Linkeind, a place for Android
developers to share, learn, and network. The resource for connecting
professionals with experience in developing, selling, marketing,
managing, supporting and/or creating new businesses around the Android
platform. We look forward to your participation and contribution!

-- 

3. Join over 3,000 developers on Linkedin

4. AudioHardwareMot

5. No emulator window in Eclipse

6. How to install Market app into emulator

7. AOSP Hero with working gstuff