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: i try to print out SAN FRANCISCO and its weather contents when practising, but i can only print the whole page. i need to print ony san francisco and its content making 4 lines altogether.

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

    Default i try to print out SAN FRANCISCO and its weather contents when practising, but i can only print the whole page. i need to print ony san francisco and its content making 4 lines altogether.

     
    import java.io.*;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.ArrayList;
    import java.util.Scanner;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.text.Document;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
     
    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException {
            // TODO code application logic here
            URL url = null;
            try {
                url = new URL("http://www.nws.noaa.gov/view/prodsByState.php?state=CA&prodtype=state");
            } catch (MalformedURLException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
     
            URLConnection uc = null;
     
            try {
                uc = url.openConnection();
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
     
            DataInputStream input = null;
            try {
                   input = new DataInputStream(uc.getInputStream());
            } catch (IOException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
     
     
        String inputLine;
        String result = null;
     
        while ((inputLine = input.readLine()) != null) {
     
            if(inputLine == "   SAN FRANCISCO")
            System.out.println(inputLine);
     
        }
     
     
        input.close();
        }
     
    }


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

    Default Re: i try to print out SAN FRANCISCO and its weather contents when practising, but i can only print the whole page. i need to print ony san francisco and its content making 4 lines altogether.

    One problem I see is the use of == to compare Strings. You should use the equals() method for comparing Strings.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. xfa.host.print: print a page + some page range.
    By gammaman in forum Totally Off Topic
    Replies: 2
    Last Post: May 10th, 2012, 08:07 AM
  2. Can't figure out how to print out number of lines and words in a file in c++
    By javapenguin in forum Other Programming Languages
    Replies: 1
    Last Post: January 29th, 2012, 07:53 PM
  3. Replies: 0
    Last Post: May 25th, 2010, 08:19 AM
  4. How to print out data from web page to printer????
    By verma86 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: April 2nd, 2010, 10:26 PM
  5. Print Content on Pre Printed Sheet
    By kalees in forum Java Theory & Questions
    Replies: 0
    Last Post: February 24th, 2010, 03:26 AM