how to determine if a file exists in a directory with FileNotFoundException

by Ohiotech » Tue, 26 Apr 2011 03:33:41 GMT


Sponsored Links
 I've been working with Eclipse ADT for about 2 months. In that time I
have a small utility that allows me to select an IP Address and Port,
and then send a file to that combo. The utility works as intended, but
when I type in the wrong file name, the application hangs.

@Override
   public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }
   }

I've even tried to do the following in hopes that one or the other
would throw, but I am unsuccessful in both.

public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }try {
         throw new Exception("blah blah blah");
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

I've jockeyed around the exception, I've added the one above, I've
tried placing it in different places, and all unsuccessful. Again, I'm
exceptionally new to this, and got here from basically mincing various
tcp client codes. Aside of creating a way to throw the exception
correctly, please help me understand why the first one isn't working
and why the one you suggest is.

-- 



Re: how to determine if a file exists in a directory with FileNotFoundException

by TreKing » Tue, 26 Apr 2011 07:08:32 GMT


 



Pause your debugger to see *where* it's hanging.

-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Other Threads

1. How can I determine if app is running on the emulator or a device.






--~--~---------~--~----~------------~-------~--~----~

2. commitUpdates with ContentProvider.update / ContentProvider.delete issue/misunderstanding?

Hello,

I am trying to write logs for ContentProvided data is created, updated
and deleted. Thus I added Log.i(MYLOG, "update") in my ContentProvider
class as follow:


    @Override
    public int update(Uri url, ContentValues values, String where,
            String[] whereArgs)
    {
        Log.i("MyLog", "update");
...
}

The above does not seem to be called... Ever... I tryed to debug as
well. Same result the update method seems to never be called....

Anybody else experiencing the same problem?
I take it that Cursor.commitUpdates() should call
ContentProvider.update()?

Thanks,
Carl
--~--~---------~--~----~------------~-------~--~----~

3. How to get pictures files?

4. Unable to set the image on an ImageView in code

5. OpenGL ES Frame Buffers

6. How to change menu background and "More" button image?

7. Resources in the base system theme