Searching a sequence from a text file entered at command line


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Searching a sequence from a text file entered at command line

  1. #1
    Join Date
    Feb 2006
    Posts
    3

    Thumbs up Searching a sequence from a text file entered at command line

    Hi there
    I am a Java newbie so if you want to ignore me with reviled distaste that is ok


    I am just looking for some advice:

    I want to create a program that checks a .txt file entered at the first line by the user (command line?) against a particular string of letters (sequence?).

    I have decided to separate my program into a few stages:
    1. Welcome and ask for File to be searched
    If not in same directory, program terminates asking to check whether file is in same directory.
    If in same directory, move onto stage 2
    2. Read file to make sure that there are just letters (i.e no numbers)
    If there are numbers, program terminates asking for numbers to be removed from .txt file.
    If there are no numbers, program continues to stage 3
    3. Read file to make sure there are no spaces. If spaces exist then join them.
    4. If letters are in small then capitalise them.
    5. If I wanted to find a word all the words beginning with a and ending with z in the text then I coul also use a*z

    I will post updates to let you know how I am doing
    If anyone can help. Thanks

  2. #2
    Join Date
    Feb 2006
    Posts
    3
    import java.io.*;

    public class CopyBytes {
    public static void main(String[] args) throws IOException {

    boolean exists = (new File("farrago.txt")).exists();
    if (exists) {
    System.out.println("File is in same directory as program. Thank You");
    // File or directory exists
    } else {
    System.out.println("File is not in directory. Please check that file is in same directory as program. Thank You");
    // File or directory does not exist
    }

    I have got the following for the first part, but I know this will only check whatever is in farrago.txt . Is there anyway to convert the above to only check for a file entered at the command line?

  3. #3
    Join Date
    Feb 2006
    Posts
    3

    Thumbs up Try 2

    What I have tried doing si scombining some of the classic Read Name program with the second part:

    import java.io.*;

    public class Mean {
    public static void main(String[] args) throws IOException {

    System.out.print("Enter your filename: ");

    // open up standard input
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    WHAT DOES ALL OF THIS MEAN?


    String userName = null;

    // read the username from the command-line; need to use try/catch with the
    // readLine() method
    try {
    userName = br.readLine();
    } catch (IOException ioe) {
    System.out.println("IO error trying to read your name!");
    System.exit(1);
    }

    boolean exists = (new File(BufferedReader)).exists();
    if (exists) {
    System.out.println("File is in same directory as program. Thank You");
    // File or directory exists
    } else {
    System.out.println("File is not in directory. Please check that file is in same directory as

    program. Thank You");
    // File or directory does not exist
    }

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Are you looking just for file names or are you looking to input a "search phrase" and then wanting to scan the content of files in a location for that phrase?

Similar Threads

  1. wav file fade in out help
    By jase_dukerider in forum C++
    Replies: 2
    Last Post: 04-14-2005, 08:48 PM
  2. Replies: 8
    Last Post: 03-08-2003, 07:25 PM
  3. Replies: 1
    Last Post: 03-06-2001, 09:42 AM
  4. Replies: 2
    Last Post: 11-30-2000, 02:17 PM
  5. Replies: 0
    Last Post: 04-17-2000, 02:33 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center