1 2 Previous Next 28 Replies Latest reply: Jun 16, 2008 3:42 PM by notivago Go to original post RSS
      • 15. Re: extracting lines from a text file
        796447
        MinzPinz wrote:
        If u do not want to help, fine with me but stop commenting! Don't waste ur time.
        You do not get to dictate what I can do here.

        In an admittedly backhanded way, I am telling you that you're wasting your time trying to dump your homework here.

        Tick tock tick tock - the homework clock is relentlessly ticking. Better get busy.
        • 16. Re: extracting lines from a text file
          807591
          Let me know if u have anymore questions
          What's your question? Namely, what is preventing you from accomplishing your goal?

          ~
          • 17. Re: extracting lines from a text file
            807591
            I am not able to display the desired line as mentioned in my previous post, I am stuck so asking for help!
            • 18. Re: extracting lines from a text file
              807591
              I am not able to display the desired line as mentioned in my previous post
              Why not?

              ~
              • 19. Re: extracting lines from a text file
                807591
                Tick tock tick tock ........ you have so much free time, good for you! I am stuck, you cud as well help me with the problem
                • 20. Re: extracting lines from a text file
                  807591
                  MinzPinz wrote:
                  Tick tock tick tock ........ you have so much free time, good for you! I am stuck, you cud as well help me with the problem
                  sigh

                  What do you mean by display?
                  • 21. Re: extracting lines from a text file
                    807591
                    This is new Sample text:
                    /**
                    [Notices]
                    [Page 11405]
                    [DOCID:fr07mr06-81]
                    --------------------------------------------------------------------------------

                    DEPARTMENT OF THE INTERIOR

                    Bureau of Land Management

                    [WY-920-1310-01; WYW144809]

                    Wyoming: Notice of Proposed Reinstatement of Terminated Oil and
                    Gas Lease WYW144809 */

                    Look at the above sample text.
                    1) I need to display/output the line in bold (Bureau of Land Management) which is the title for this sample text.
                    2) For this I need to find index of DOCID , remove
                    --------------------------------------------------------------------------------
                    line, remove uppercase line and then grab the next line of text.
                    3) As the title line is always found after DOCID, this is the logic I think is the best way to grab the desired line
                    4) In my code I have only the index of DOCID, after that I am not able to go furthur.
                    The code I have so far is

                    public class Title {
                         public static void readLines(String fileName) {
                              String line;
                     
                              try {
                                   FileReader file = new FileReader(fileName);
                                   BufferedReader buffer = new BufferedReader(file);
                                   while((line = buffer.readLine()) != null) {
                     
                                        if (line.indexOf("DOCID:")>=0)
                                             
                                   buffer.close();
                                   
                              } catch(IOException e) {
                                   e.printStackTrace();
                              }
                         } 
                    }
                    • 22. Re: extracting lines from a text file
                      807591
                      MinzPinz wrote:
                      This is new Sample text:
                      Please stop posting this crap.

                      What do you mean by "display"?
                      • 23. Re: extracting lines from a text file
                        807591
                        output
                        • 24. Re: extracting lines from a text file
                          807591
                          MinzPinz wrote:
                          output
                          To your shredder? To the serial port? To a web page?
                          • 25. Re: extracting lines from a text file
                            807591
                            web page
                            • 26. Re: extracting lines from a text file
                              807591
                              MinzPinz wrote:
                              web page
                              Well your code looks nothing like a Servlet ( or even JSP) so that's going to be a problem.

                              Are you sure you want to display to a web-page or are you just grasping at straws and you really meant to say console?
                              • 27. Re: extracting lines from a text file
                                notivago
                                The reason why you are unable to go any further in reading your file is that you have an buffer.close() right when you find the docid. First thing avoid writing if blocks without {}, it is a common source of mistakes. Besides that, you got to have any code that does print anything. It seems to me that you are going for steps larger than your legs allow. First write your code so that is outputs all the text, when you get that working, figure what you must include to prevent what you do not want from printing.
                                • 28. Re: extracting lines from a text file
                                  800472
                                  notivago pointed out the obvious semantic error in your program. You should correct it.

                                  The requirements you stated seem unnecessarily complicated given your sample text. It looks like you just want to read 4 lines past what you are currently, so why not code it to find the line with DocID, read 4 more lines, and then treat the next line as your target?

                                  If you have no idea how to begin, you should pseudocode this. Break it down into simple, discrete, logical steps written in plain english, and then focus on just one step at a time, making sure it works correctly before moving on to the next. If you can pseudocode it a lot of people here will be happy to show you how to turn that into java code, but currently it looks as if you haven't actually done any work yourself. You already know how to test if a line contains a string, and how to advance to the next line, because the code you're posting does that.
                                  1 2 Previous Next