Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-04-2008, 08:12 PM
Member
 
Join Date: May 2008
Posts: 2
JavaHead08 is on a distinguished road
Downloading part of a file with java? What have I done wrong?
I'm trying to create a program that will download only a portion of a file. From everything I could find on the subject I'm doing it correctly, but the program still downloads the entire file. What have I done wrong? Is it possible to do what I'm trying to do with Java? Can someone please point me in the right direction? Thank you. The code is below.

Code:
import java.io.*; import java.net.*; public class FileDownload2 { public static void download() { OutputStream out = null; RandomAccessFile file = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL("http://www32.megaupload.com/files/c7c6f4ce249c6ccad7583a8f6ea943a8/Kanye%20West%20Nas%20&%20KRS-One%20-%20Classic%20(Midas%20Touch%20Remix).mp3"); conn = url.openConnection(); conn.setRequestProperty("Range", "901600-"); in = conn.getInputStream(); byte[] buffer = new byte[1024]; out = new FileOutputStream("test"); int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } } catch (Exception exception) { exception.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void main(String[] args) { download(); } }
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
[SOLVED] Downloading jconn3.jar DonCash Database 1 04-15-2008 06:02 PM
Payroll Part 2, Java lplopez92 New To Java 2 03-24-2008 02:55 PM
Help with mathematical part in java lenny Advanced Java 3 08-09-2007 02:55 PM
Problems with downloading Files from Applet Albert Java Applets 1 07-05-2007 06:09 AM
Part time java Programmer-Indianapolis,IN pegitha Jobs Offered 0 05-08-2007 05:01 PM


All times are GMT +3. The time now is 04:04 PM.


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