View RSS Feed

Recent Blogs Posts

  1. Reading an ASCII file (BufferedReader)

    by , 11-10-2011 at 06:14 PM (My Java Tips)
    Normally we give input to Java applications from command prompt or through GUI. But sometimes, when inputs are in bulk, we can use ASCII files for input. Such files must have some agreed upon pattern so Java parser can understand the meaning of the text. There are many ways to read a file but one of the simplest way is to use BufferedReader class which is found in java.io package.


    First prompt the user to enter the file name with path. This can be done using:

    Java Code:
      
    ...
    Categories
    Java SE
  2. Fetching HTML content of a Web Page

    by , 11-10-2011 at 05:46 PM (My Java Tips)
    Sometimes you are required to fetch and store data from web pages. If there are too many pages to parse, then obviously this cannot be done manually. Java provides support for web text extraction.


    The approach is simple. You have to fetch all the HTML contents of a webpage and then you can write your own parser to extract the required info. For example: you might be asked to only store the text in table data tag with caption Hobbies. So you will store all the HTML contents of web ...
  3. Taking inputs from users

    by , 11-08-2011 at 07:28 PM (My Java Tips)
    There are a number of ways to take input from user in Java.
    Following code sample helps you in taking input as a character, as a stream and from GUI.
    Required Packages: import java.io and javax.swing packages.



    Java Code:
    // reading character from user
    char a = (char)System.in.read();
    System.out.println("Character read is: " + a);
    
    // taking input from GUI
    String input = JOptionPane.showInputDialog("What is your name?");
    ...