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. Latin characters in EditText Android

Hi everyone,
   Does anyone know how can i use Latin characters such as     in
android?
   All my EditText components do not accept it, neither does the Contacts
Application for instance.

   Whenever i raise my application and emulator i get the following error:
     Application Android Keyboard (in process com.android.inputmethod.latin)
is not responding.

    I don't know if this problem is related, but i think so.


can anyone help me out?


-- 
Murilo Costa
muri...@gmail.com
twitter.com/murilobtc

-- 

2. Android Emulator problem

Hi,

I'm having trouble with the Android Emulator. Whenever I use the run
or debug commands out of Eclipse, it shows the phone, but it only
shows Android and the logo on the screen. Nothing makes it show my
app.
I've tried tweaking emulator settings, but no luck.

What can I do to solve this problem?

Thanks,
-Maximz2005

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

3. What does targetSdkVersion do?

4. Android groups access method

5. accessing and changing Sync setting for android 1.5, 1.6 and more

6. onSharedPreferenceChanged() Not Called in Live Wallpaper (WallpaperService) Engine

7. java.nio IntBuffer.get perfomance problem