Results 1 to 6 of 6

Thread: Search TextFile

  1. #1
    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0

    Default Search TextFile

    .....................................
    Last edited by gsupriyarao@yahoo.com; 04-14-2008 at 03:08 AM. Reason: delete

  2. #2
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Do you have an example input file and desired output?

    Are you happy to have it read in line by line and search that string for the word?
    Did this post help you? Please me! :cool:

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    So once it finds a word it will show the 2 words to the left on the same line and then print out the 2 words to the right but with a new line after each of these?
    Did this post help you? Please me! :cool:

  4. #4
    tress is offline Member
    Join Date
    Mar 2008
    Location
    Florida Johannesburg
    Posts
    2
    Rep Power
    0

    Red face Prime numbers

    Does anyone know how to check if a number is prime or not:p

  5. #5
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Tress, why have you posted this unrelated question here? It would make more sense to start a new thread!

    Please bare that in mind in the future. Anyway, use this code:

    Java Code:
    public class prime {
    		 
    public static void main(String[] args) {    
    
    int num; 
    int i; 
    int factor; 
    boolean isprime; 
    		 
    for(num = 2; num < 20; num++) { 
    isprime = true;  
    factor = 0; 
    
    // see if num is evenly divisible 
    for(i=2; i <= num/2; i++) { 
    if((num % i) == 0) { 
    
    // num is evenly divisible -- not prime 
    isprime = false; 
    factor = i; 
    } 
    } 
    		 
    if(isprime) 
    System.out.println(num + " is prime."); 
    else 
    System.out.println("Largest factor of " + num + " is " + factor); 
       } 
     }    
    }
    Did this post help you? Please me! :cool:

  6. #6
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    I'm still trying to figure out how to do this. Ill post some code as soon as possible.

    To start though, here is the code to read in a document line by line:

    Java Code:
    FileInputStream in = new FileInputStream("file_path/file.txt");
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    
    String strLine;
    
    while ((strLine = br.readLine()) != null) {
    System.out.println(strLine);
    }
    Did this post help you? Please me! :cool:

Similar Threads

  1. ECG plot in a textfile
    By samson in forum Java 2D
    Replies: 13
    Last Post: 01-28-2012, 05:02 PM
  2. reading textfile from java problem
    By saytri in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 03:13 AM
  3. textfile with Java problems
    By saytri in forum New To Java
    Replies: 4
    Last Post: 12-29-2007, 06:16 PM
  4. Textfile and GUI problems
    By saytri in forum New To Java
    Replies: 2
    Last Post: 12-21-2007, 05:08 PM
  5. Problem with storing and retrieving from a textfile
    By Albert in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •