Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008, 09:10 PM
Member
 
Join Date: Jun 2008
Posts: 2
hknyo is on a distinguished road
java file copy
hello,
I am trying to copy files from network to local disk. I have this working using URL and inputStream. my problem is that I want to throw exception for both connection failure and filenotfound . I tested with different scenerios and I could not get filenotfound exception. it keeps saying that connection error , here is a breif list of what i am doing

-get file using url
-check if the connection fail, if fail return error message
-if connection is good, proceed and get file
-if file does not exist on the source machine, throw filenotfound and return error message
-if every goes well, copy over the file to localdisk.

here is partial code

...
host = "file:\\\\sourceMachine\\content\\BIGfile.big" ;
URL url = new URL(host);
URLConnection urlC = url.openConnection();
// Copy resource to local file
InputStream is = url.openStream();
System.out.flush();
FileOutputStream fos = null;

String localFile = null;

// Get only file name
StringTokenizer st = new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens()) {
localFile = st.nextToken();
}

fos = new FileOutputStream(localFile);

byte[] buf = new byte[32768];
int len;
while ((len = is.read(buf)) > 0) {
fos.write(buf, 0, len);
}

is.close();
fos.close();

} catch (IOException e) {

e.printStackTrace()

}

everytime, i change the invalid machine name, it gives me unknownhost error(which is correct), but when I tried to change invalid filename it gives me conenction error (java.net.ConnectException: Connection refused: connect) but this is not what i want, i want file not found exception. anyone help me on this. thanks.

Cheers
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-12-2008, 06:42 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,609
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Check that your URL, is it correct? What you have done there. It's not a valid url to make a connection though.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy a .swf file from server side to client using signed applet Imoracle Java Applets 2 10-05-2008 08:13 PM
java copy paste cut and undo functions Mr tuition AWT / Swing 1 12-09-2007 02:02 AM
copy image/imageicon into a file on disk archanajathan Advanced Java 2 11-22-2007 08:21 AM
Problem with array Copy coco New To Java 1 08-07-2007 09:46 AM
how to issue the command of Ctrl-C (copy) in Java bilal_ali_java Advanced Java 0 07-18-2007 05:14 PM


All times are GMT +3. The time now is 02:35 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org