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 5 of 5

Thread: File Reading from the specified location

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default File Reading from the specified location

    Hi All,
    i am new to java, have one requirement.

    I need to process the file ---For Ex. input file is having 1000 records . i need to process the first 100 records after that in the second iteration 101-200,third iteration,201-300.......like this i need to process all the records.

    can anyone help me?


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: File Reading from the specified location

    Hello and welcome,

    What exactly is your problem, is it opening the file and reading the data or the actual iteration code?

    // Json

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: File Reading from the specified location

    Hello rajesh.mv. Welcome to the Java Programming Forums.

    Do you know exactly how many lines there will be each time? Will there always be 1000 lines?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: File Reading from the specified location

    I'm not sure if this will work as expected but try this:

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
     
    public class FileReader {
     
        /**
         * JavaProgrammingForums.com
         */
     
        public static int lineNumber;
        public static String myFile = "inputfile.txt";
     
        public void doStuff() {
     
            switch (lineNumber) {
            case 100:
                System.out.println("100 lines");
                break;
            case 200:
                System.out.println("200 lines");
                break;
            case 300:
                System.out.println("300 lines");
                break;
            case 400:
                System.out.println("400 lines");
                break;
            case 500:
                System.out.println("500 lines");
                break;
            case 600:
                System.out.println("600 lines");
                break;
            case 700:
                System.out.println("700 lines");
                break;
            case 800:
                System.out.println("800 lines");
                break;
            case 900:
                System.out.println("900 lines");
                break;
            case 1000:
                System.out.println("1000 lines");
                break;
            default:
                break;
            }
     
        }
     
        public void readMe() {
     
            try {
                FileInputStream in = new FileInputStream(myFile);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String strLine;
     
                while ((strLine = br.readLine()) != null) {
                    //System.out.println(strLine);
                    lineNumber++;
                    doStuff();
                }
     
            } catch (Exception e) {
                System.out.println("Problem reading file! " + e);
            }
        }
     
        public static void main(String[] args) {
     
            FileReader fr = new FileReader();
            fr.readMe();
     
            System.out.println("Total number of lines: " + lineNumber);
     
        }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member
    Join Date
    Aug 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: File Reading from the specified location

    I got the solution for that issue.Thanks for your replies

Similar Threads

  1. How to find location of ipaddress using Java
    By tej in forum Java Networking
    Replies: 8
    Last Post: September 8th, 2012, 06:05 AM
  2. setting location of a dialog relative to the parent
    By dewboy3d in forum AWT / Java Swing
    Replies: 1
    Last Post: August 1st, 2009, 05:42 PM
  3. Problem on reading file in Java program
    By nathanernest in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: April 13th, 2009, 08:14 AM
  4. [SOLVED] Program to read from created file
    By aznprdgy in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 7th, 2009, 03:51 AM
  5. [SOLVED] Problem in reading a file from java class
    By aznprdgy in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: March 23rd, 2009, 09:31 AM