File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Finding poistion (Line Number) of text in a given File. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finding poistion (Line Number) of text in a given File." Watch "Finding poistion (Line Number) of text in a given File." New topic
Author

Finding poistion (Line Number) of text in a given File.

Sneha Teck
Greenhorn

Joined: Mar 20, 2007
Posts: 7
Hi,

I have to find the Line Number of a 'text' from within a given file.

The file name and the 'text' is available.

Appreciate any help in achieving this .


Thanks.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14428
    
  23

Here are some pointers:

  • Example: Read a text file line by line
  • You might want to use class java.io.LineNumberReader (lookup the API documentation)
  • There are methods in class String to find out if a string contains a certain text (lookup the API documentation)


  • Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    Monika Joshi
    Greenhorn

    Joined: Apr 19, 2010
    Posts: 9
    Hi,

    Here is the pseudocode. This should work.

    [Jesper Young: solution deleted]

    Regards,
    Minakshi
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14428
        
      23

    Minakshi, welcome to JavaRanch.

    I deleted your solution, because on JavaRanch we have a policy that we want to encourage people to learn - giving people complete solutions to their programming assignments does not help people learn. So, thank you for your contribution, but please don't post complete solutions. (And a tip: UseCodeTags when you post source code).
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Finding poistion (Line Number) of text in a given File.