Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 41
Like Tree4Likes

Thread: Download All Files from a Directory

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    I thought that you had a method: download() that would read a file. All you need after that file is read is code to read the lines from that file and use your method to read each file that was listed in the file that was downloaded.
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Arrow Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    I thought that you had a method: download() that would read a file. All you need after that file is read is code to read the lines from that file and use your method to read each file that was listed in the file that was downloaded.
    Yes, it's going through the file that's downloaded that I need help on. I don't know how to read files, I'm a noob

  3. #23
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    An easy way to read text files is to use the Scanner class and it set of methods like next() and nextLine().
    To learn the techniques: write a small simple program that reads the lines in a text file and prints them on the screen.
    When that works, copy the logic into the program you are writing for this project.
    Last edited by Norm; 12-14-2013 at 01:06 AM.
    If you don't understand my response, don't ignore it, ask a question.

  4. #24
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Default Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    An easy way to read text files is to use the Scanner class and it set of methods like next() and nextLine().
    To learn the techniques: write a small simple program that reads the lines in a text file and prints them on the screen.
    When that works, copy the logic into the program you are writing for this project.
    So this means I would need a
    Java Code:
    for
    or
    Java Code:
    while
    loop correct, then I would just repeatedly run
    Java Code:
    download(place, filenamestringthingyofawesomeness);
    instead of
    Java Code:
    System.out.println(filenamestringthingyofawesomeness);
    right?

  5. #25
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    Yes, the code would use a loop and for testing it would use a println().
    If you don't understand my response, don't ignore it, ask a question.

  6. #26
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Arrow Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    Yes, the code would use a loop and for testing it would use a println().
    So the structure of the the code would technically be
    Java Code:
    while(linesUnreadStillInFile) {
        
        download(placeToDownload, fileURL);
        System.out.println("Downloaded " + fileURL + " to " + placeToDownload);
        
    }
    right?

  7. #27
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    You left out the reading of the file that has the list of files to be downloaded.
    If you don't understand my response, don't ignore it, ask a question.

  8. #28
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Default Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    You left out the reading of the file that has the list of files to be downloaded.
    Java Code:
    public static String file = "downloadedFilePlace";
    while(linesUnreadStillInFile(file)) {
         
        download(placeToDownload, fileURL);
        System.out.println("Downloaded " + fileURL + " to " + placeToDownload);
         
    }

  9. #29
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    Lots of code hidden in the methods and the location of variable definitions, but that could work.
    If you don't understand my response, don't ignore it, ask a question.

  10. #30
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Wink Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    Lots of code hidden in the methods and the location of variable definitions, but that could work.
    Alright, I've made the file reader, and it reads the file correctly, here's my code, so all I need to do is replace
    Java Code:
    System.out.println(sCurrentLine);
    with
    Java Code:
    download(sCurrentLine);
    ,
    Java Code:
    public static void readIt(String file) {
    		
    		try (BufferedReader br = new BufferedReader(new FileReader(file))) {
    			
    			String sCurrentLine;
     
    			while ((sCurrentLine = br.readLine()) != null) {
    				
    				System.out.println(sCurrentLine);
    				
    			}
    		
    		} catch (IOException e) {
    			
    			e.printStackTrace();
    			
    		} 
    		
    	}

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    OK, how is that going now? Have you tried it? What happens?
    If you don't understand my response, don't ignore it, ask a question.

  12. #32
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Default Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    OK, how is that going now? Have you tried it? What happens?
    I have tried it, it prints out the lines of the file separately, the file reads [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y, z] and prints those each on separate lines, so I can see that it would read each of the lines of that first file :)

  13. #33
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    Is that what you expected?
    If you don't understand my response, don't ignore it, ask a question.

  14. #34
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Arrow Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    Is that what you expected?
    Yes! I'm pretty much done now :)
    Could I ask you, I don't know if you know, but what is the Windows path to appdata, like typing %appdata% in your search, but what's the exact path?

  15. #35
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    What is appdata?

    To see the currently set environment variables, open a command prompt window and enter: Set
    If you don't understand my response, don't ignore it, ask a question.

  16. #36
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Default Re: Download All Files from a Directory

    Quote Originally Posted by cjburkey01 View Post
    So could I have an example of how it would read the file and download each file?
    Hmm, do you have Windows? if so, 8 or 7?
    If you have 7, it's where most of your program data and information is stored, for Minecraft players(on windows) to install stuff, we would click the home button, type "%appdata%" press enter and open the Minecraft folder. And I've got the check OS down, I was just wondering if you knew the file path to appdata :P

  17. #37
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    open a command prompt window and enter: Set
    If you don't understand my response, don't ignore it, ask a question.

  18. #38
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Default Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    open a command prompt window and enter: Set
    What?

  19. #39
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default Re: Download All Files from a Directory

    What is the "what" asking about?

    Command prompt window

    Opening a command prompt window

    Entering a Set command in the command prompt window.
    If you don't understand my response, don't ignore it, ask a question.

  20. #40
    cjburkey01 is offline Member
    Join Date
    Dec 2013
    Posts
    20
    Blog Entries
    2
    Rep Power
    0

    Arrow Re: Download All Files from a Directory

    Quote Originally Posted by Norm View Post
    What is the "what" asking about?

    Command prompt window

    Opening a command prompt window

    Entering a Set command in the command prompt window.
    I use Mac, I was wondering if anyone could give me the exact Windows %appdata% folder thing. I'm making it download mods to the minecraft folder, and I don't know the windows path.

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Download large files from web
    By Asolpdrag in forum New To Java
    Replies: 3
    Last Post: 02-04-2012, 05:47 PM
  2. Download Files From A Website
    By anthropamorphic in forum Networking
    Replies: 3
    Last Post: 10-28-2011, 03:45 AM
  3. download files from internet
    By sublixt in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2011, 12:30 AM
  4. How to. Files and Directory
    By ocean in forum New To Java
    Replies: 4
    Last Post: 12-06-2009, 06:23 PM
  5. Replies: 2
    Last Post: 03-28-2009, 06:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •