Nov 20 | 9:55 AM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 20 | 10:00 AM |
Guy | has entered the room |
Mark M. |
hello, Guy!
|
Mark M. |
how can I help you today?
|
Guy |
hi :-)
|
Mark M. |
do you have a question?
|
Nov 20 | 10:05 AM |
Guy |
sorry about that
|
Guy |
my internet went loopy
|
Mark M. |
that happens from time to time :)
|
Nov 20 | 10:10 AM |
Guy |
well I rewrote my currency app. used as you advised FILE I/O
|
Guy |
if I want to check the "freshness" of the file downloaded, should I check when was it last modifed?
|
Mark M. |
do you modify the file yourself?
|
Guy |
no
|
Guy |
I download it from the internet
|
Mark M. |
then the last-modified timestamp should be stable
|
Mark M. |
if you are worried about something touching the file and updating that timestamp after the download, you will need to do something else
|
Guy |
I use it as a satstic file
|
Nov 20 | 10:15 AM |
Mark M. |
if you have any other questions, go ahead -- it's a quiet chat room today
|
Guy |
View paste
|
Guy |
should it be like that?
|
Mark M. |
well, lastModified() is how you get the last-modified time of a File
|
Mark M. |
however, that returns a long
|
Nov 20 | 10:20 AM |
Mark M. |
format() does not take a long
|
Mark M. |
it takes a Date
|
Mark M. |
you would use format(new Date(file.lastModified())) AFAIK
|
Mark M. |
and I am not sure what the SimpleDateFormat is for, other than for logging purposes
|
Guy |
thanks. I'll figure that out later :-)
|
Guy |
the next question is about closing the file stream
|
Guy | |
Nov 20 | 10:25 AM |
Guy |
(line 40) FileInputStream
|
Guy |
do I need to close() it?
|
Mark M. |
you should
|
Mark M. |
I think the standard pattern would have your lines 35-40 above the try
|
Mark M. |
and then use a finally {} block to close the stream
|
Mark M. |
it may be you wind up needing two nested try {} blocks, as openFileInput() could fail with a FileNotFoundException
|
Guy |
OK
|
Devin F. | has entered the room |
Nov 20 | 10:30 AM |
Guy |
lines 35-40 eclipse gone red "Unhandled exception type XmlPullParserException" demannds try catcg
|
Mark M. |
yeah, you will need nested try {} blocks there, then
|
Mark M. |
let me take a question from Devin, and I'll be back with you in a bit
|
Mark M. |
Devin: hi! do you have a question?
|
Guy |
OK :-)
|
Devin F. |
Mostly I was checking how the chat worked. The two comments I have currently are my subscription is still marked as one year too long. and teh second is that my book isn't opening from the PDF link.
|
Devin F. |
I'm not sure this is teh correct forum for either
|
Mark M. |
both are better handled via emails to wares@commonsware.com
|
Devin F. |
excellent. Thanks.
|
Mark M. |
with respect to the subscription length, for the few people who were double-billed before I improved the site, I just elected to give you the extra year for the annoyance and hassle I put you through
|
Mark M. |
with respect to the PDF, if you can send me an email with more details, I can help you better there
|
Mark M. |
the chats are for help with Android development questions
|
Devin F. |
thanks heaps. I'll come by for office hour development questions as soon as I'm further along in the book.
|
Mark M. |
Guy: do you have another question?
|
Nov 20 | 10:35 AM |
Guy |
not at the moment. Thank You :-)
|
Mark M. |
OK, well, if either of you have a question, feel free to chime in
|
Nov 20 | 10:40 AM |
Guy | |
Mark M. |
stream.close()
|
Guy |
i thought stream.close();
|
Mark M. | |
Guy | |
Mark M. |
you need to make sure that stream is declared and initialized outside the try {} associated with the finally {}
|
Nov 20 | 10:45 AM |
Guy | |
Guy |
View paste
|
Guy |
like this
|
Guy |
?
|
Mark M. |
depending upon your overall structure, you may not need the try/catch around close(), if there is an outer try that would catch the exception
|
Mark M. |
otherwise, generally yes
|
Guy |
there is one
|
Mark M. |
note that this is not Android-specific
|
Mark M. |
other than how you got the stream in the first place (openFileInput())
|
Mark M. |
this is standard Java file I/O
|
Guy |
yes
|
Guy |
View paste
(27 more lines)
|
Mark M. |
unless there is a try around all of that, you will need the try inside the finally block
|
Nov 20 | 10:50 AM |
Devin F. | has left the room |
Guy |
thanks.
|
Guy |
see you soon.
|
Nov 20 | 11:00 AM |
Mark M. |
that's a wrap for today's office hours chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is tomorrow at 7:30pm Eastern
|
Mark M. |
have a pleasant day!
|
Guy | has left the room |
Mark M. | turned off guest access |