Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > method to test if a file exist?

Reply
Thread Tools

method to test if a file exist?

 
 
jova
Guest
Posts: n/a
 
      04-16-2006
Is there some method I can call that can test to see if a method exist or
not?


 
Reply With Quote
 
 
 
 
jova
Guest
Posts: n/a
 
      04-16-2006
I'm sorry I meant to say if there is a method that test if a File exist or
not?
"jova" <> wrote in message news:dlg0g.362$...
> Is there some method I can call that can test to see if a method exist or
> not?
>



 
Reply With Quote
 
 
 
 
Bjorn Abelli
Guest
Posts: n/a
 
      04-16-2006

"jova" wrote...

> I'm sorry I meant to say if there is a method that test
> if a File exist or not?


Sure, e.g.:

File f = new File("filename");

if ( f.exists() )
{
// Do something with it...
}

// Bjorn A


 
Reply With Quote
 
Furious George
Guest
Posts: n/a
 
      04-16-2006

Bjorn Abelli wrote:
> "jova" wrote...
>
> > I'm sorry I meant to say if there is a method that test
> > if a File exist or not?

>
> Sure, e.g.:
>
> File f = new File("filename");
>
> if ( f.exists() )
> {
> // Do something with it...
> }
>
> // Bjorn A


Your method is too complicated. And it does not deal with the possible
thrown SecurityException. This is the preferred approach

public static boolean doesExist(java.io.File veryImportantFile)
{
try
{
veryImportantFile.delete();
return(false);
}
catch(java.lang.SecurityException e)
{
return(true);
}
}

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-16-2006
On Sat, 15 Apr 2006 20:38:32 -0400, "jova" <> wrote,
quoted or indirectly quoted someone who said :

>I'm sorry I meant to say if there is a method that test if a File exist or
>not?


see http://mindprod.com/jgloss/file.html

File.exists

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-16-2006
On 15 Apr 2006 19:23:54 -0700, "Furious George" <>
wrote, quoted or indirectly quoted someone who said :

>Your method is too complicated. And it does not deal with the possible
>thrown SecurityException. This is the preferred approach
>
>public static boolean doesExist(java.io.File veryImportantFile)
>{
> try
> {
> veryImportantFile.delete();
> return(false);
> }
> catch(java.lang.SecurityException e)
> {
> return(true);
> }
>}


Newbie alert. He is teasing.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Tony Morris
Guest
Posts: n/a
 
      04-16-2006
On Sat, 15 Apr 2006 19:23:54 -0700, Furious George wrote:

>
> Bjorn Abelli wrote:
>> "jova" wrote...
>>
>> > I'm sorry I meant to say if there is a method that test
>> > if a File exist or not?

>>
>> Sure, e.g.:
>>
>> File f = new File("filename");
>>
>> if ( f.exists() )
>> {
>> // Do something with it...
>> }
>>
>> // Bjorn A

>
> Your method is too complicated. And it does not deal with the possible
> thrown SecurityException. This is the preferred approach
>
> public static boolean doesExist(java.io.File veryImportantFile)
> {
> try
> {
> veryImportantFile.delete();
> return(false);
> }
> catch(java.lang.SecurityException e)
> {
> return(true);
> }
> }


Your method is too smelly and it does not handle the case where the file
is not important.

Prefer this:
public interface FileExists {
boolean exists(java.io.File f) throws NullPointerException;
}

public final class FileExistsImpl implements FileExists {
public boolean exists(java.io.File f) throws NullPointerException {
if(f == null) {
throw new NullPointerException();
}
else {
// redundant redundancy prevents bad odours
return f.exists() == true == true == true != false;
}
}
}

--
Tony Morris
http://tmorris.net/

s/Commonwealth Games/Commonwealth Swimming

 
Reply With Quote
 
jova
Guest
Posts: n/a
 
      04-16-2006
thanks for all ur help people that I thought it was a board that would try
to help others but, it seems like to make fun of others than actually
helping. I hope your it helped fill the voids that is missing in your life.
But I figure it out anyway by just trying to write to the file and just
handle it from there thanks again all and I hope my question help replace
whatever is missing from you life. Enjoy!!!


"Tony Morris" <> wrote in message
news...
> On Sat, 15 Apr 2006 19:23:54 -0700, Furious George wrote:
>
>>
>> Bjorn Abelli wrote:
>>> "jova" wrote...
>>>
>>> > I'm sorry I meant to say if there is a method that test
>>> > if a File exist or not?
>>>
>>> Sure, e.g.:
>>>
>>> File f = new File("filename");
>>>
>>> if ( f.exists() )
>>> {
>>> // Do something with it...
>>> }
>>>
>>> // Bjorn A

>>
>> Your method is too complicated. And it does not deal with the possible
>> thrown SecurityException. This is the preferred approach
>>
>> public static boolean doesExist(java.io.File veryImportantFile)
>> {
>> try
>> {
>> veryImportantFile.delete();
>> return(false);
>> }
>> catch(java.lang.SecurityException e)
>> {
>> return(true);
>> }
>> }

>
> Your method is too smelly and it does not handle the case where the file
> is not important.
>
> Prefer this:
> public interface FileExists {
> boolean exists(java.io.File f) throws NullPointerException;
> }
>
> public final class FileExistsImpl implements FileExists {
> public boolean exists(java.io.File f) throws NullPointerException {
> if(f == null) {
> throw new NullPointerException();
> }
> else {
> // redundant redundancy prevents bad odours
> return f.exists() == true == true == true != false;
> }
> }
> }
>
> --
> Tony Morris
> http://tmorris.net/
>
> s/Commonwealth Games/Commonwealth Swimming
>



 
Reply With Quote
 
Alex Hunsley
Guest
Posts: n/a
 
      04-16-2006
jova wrote:
> thanks for all ur


It's "your"...

> help people that I thought it was a board


Noop, it's a newsgroup. This is Usenet. You may be posting to it via
google groups, but it's usenet.

> that would try
> to help others but, it seems like to make fun of others than actually
> helping.


And what was wrong with the answer that Bjorn posted?
You obviously haven't spent any time reading any other posts if you
think that no-one gets any help.
Get over your sense of drive-by entitlement. You got a correct answer,
and these people aren't your slaves. If you're so disappointed I suggest
you demand the money back you paid for the advice.
And it seems you didn't bother to try google, which would have given you
the answer in a snap, if you'd searched for "java check if file exists"
or similar.


> I hope your it helped fill the voids that is missing in your life.


One of the reasons some people didn't take your question too seriously
is that you're asking a question which is quite easily answerable by
using google. It sometimes looks lazy when people ask questions that
could have been answered well by google. (Isn't necessarily actually
lazy; sometimes the poster doesn't realise that google is so useful at
answering questions that way, or isn't sure of the search terms.)

Hint: anyone who posts questions that include "... and I tried to google
for phrase 'X' but I didn't turn up anything..." is regarded a little
more seriously, I find. It doesn't mean that you won't get help if you
don't saying you used google, though.

> But I figure it out anyway by just trying to write to the file


Or you could use Bjorn's answer, which is correct.

> and just
> handle it from there thanks again all and I hope my question help replace
> whatever is missing from you life. Enjoy!!!


Don't take umbrage because some people had a little fun. Remember,
you're not paying them for this.


 
Reply With Quote
 
jova
Guest
Posts: n/a
 
      04-16-2006

"Alex Hunsley" <> wrote in message
news:vyl0g.67155$. uk...
> jova wrote:
>> thanks for all ur

>
> It's "your"...
>
>> help people that I thought it was a board

>
> Noop, it's a newsgroup. This is Usenet. You may be posting to it via
> google groups, but it's usenet.
>
>> that would try to help others but, it seems like to make fun of others
>> than actually helping.

>
> And what was wrong with the answer that Bjorn posted?
> You obviously haven't spent any time reading any other posts if you think
> that no-one gets any help.
> Get over your sense of drive-by entitlement. You got a correct answer, and
> these people aren't your slaves. If you're so disappointed I suggest you
> demand the money back you paid for the advice.
> And it seems you didn't bother to try google, which would have given you
> the answer in a snap, if you'd searched for "java check if file exists" or
> similar.
>
>
>> I hope your it helped fill the voids that is missing in your life.

>
> One of the reasons some people didn't take your question too seriously is
> that you're asking a question which is quite easily answerable by using
> google. It sometimes looks lazy when people ask questions that could have
> been answered well by google. (Isn't necessarily actually lazy; sometimes
> the poster doesn't realise that google is so useful at answering questions
> that way, or isn't sure of the search terms.)
>
> Hint: anyone who posts questions that include "... and I tried to google
> for phrase 'X' but I didn't turn up anything..." is regarded a little more
> seriously, I find. It doesn't mean that you won't get help if you don't
> saying you used google, though.
>
>> But I figure it out anyway by just trying to write to the file

>
> Or you could use Bjorn's answer, which is correct.
>
>> and just handle it from there thanks again all and I hope my question
>> help replace whatever is missing from you life. Enjoy!!!

>
> Don't take umbrage because some people had a little fun. Remember, you're
> not paying them for this.
>
>


I did try it and I read the jdk help I seen no such method as Bjorn stated.
My question was plain and simple I ask if was there any method such as that
"I could check if the file existed". I didn't see an adequate reply to my
question. Then, I get such people trying to to make fun of my question.
I'm sorry for the incorrect spelling of "urs" but you knew exactly what I
meant or did you just like I may or may not understand what "I tried to
google" mean as well. Did you mean search the internet for solution to my
problem or something else because google is not in the dictionary sorry.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
test test test richard Computer Support 3 01-24-2007 05:18 AM
TEST TEST Test...Blah Blah Blah generalbatguano@pacbell.net Computer Support 2 09-15-2006 03:47 AM
TEST TEST Test...Blah Blah Blah Generalbatguano@pacbell.net Computer Support 6 09-13-2006 01:53 AM
TEST TEST TEST Gazwad Computer Support 2 09-05-2003 07:32 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57