Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need Help With Coding

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help With Coding

    Hello all, I am looking for some help with some hw I have in a computer class. We are doing a little Java but I am pretty new with the whole language so am having a tough time. Any help would be greatly appreciated!

    I have been given these rules to follow-
    iStream is an instance variable that is an InputStream object.
    openInput is a method that takes in a String that is the url address to an input file somewhere on the web. Then, you must use that String to create a new URL object, and create a URLConnection object by opening a connection to the URL object. Finally, get an InputStream from the URLConnection object, and use it to set the value of iStream. All exceptions must be caught.

    download is a method that takes in a String that is the directory path/filename of the local file where the information from the web should be written. This method should use a Scanner object to read information from the InputStream iStream and copy it line-by-line into the local file using a FileWriter object. This method must return true if the copy was successful, and return false if the copy was unsuccessful (i.e., file does not exist). All exceptions must be caught.

    So far I have this-
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
     
    public class WebReader_A7part2 {
     
    	InputStream iStream;
     
    	Private void openInput(String urlAddress)
     
    	    Private URL myURL = new URL(urlAddress);
    	    URLConnection myURLConnection = myURL.openConnection();
    	    myURLConnection.connect();
    	    BufferedReader br = new BufferedReader(new InputStreamReader(
                    myURLconnection.getInputStream()));
    	    ObjectInputStream ois = new ObjectInputStream(myURLConnection);
    	    String inputLine;
            while ((inputLine = br.readLine()) != null) 
                System.out.println(inputLine);
            br.close();
    	} 
     
    	boolean download(String filePath)
    	Private void Scanner sc = new Scanner(iStream);
     
    	boolean copyContents(File A, File B){
     
    	try{
    			if(A.exists() & B.exists()){
     
    				InputStream in = new FileInputStream(A);
    				OutputStream out = new FileOutputStream(B);

    I am having issues using a scanner object to read from the inputstream iStream and copy it line by line using a filewriter object. Any help!?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Need Help With Coding

    I am having issues using a scanner object to read from the inputstream iStream and copy it line by line using a filewriter object.
    Please explain what your problems are.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. java coding
    By deq wan in forum Member Introductions
    Replies: 1
    Last Post: April 14th, 2012, 08:48 AM
  2. Need help with Huffman coding, please?
    By knguye in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2012, 07:36 AM
  3. Coding Problem
    By BohmfalkCW in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 26th, 2012, 06:10 PM
  4. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  5. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM