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

Thread: write lines which start without cahracter

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default write lines which start without cahracter

    NB: thread heading is littele bit wrong, I want to exclude lines from writing to output which start with specific character
    human
    donkey
    monkery
    I want to write human and monkey, and exclude line which starts with "d"-donkey.


    Is there built in method or smthng to say to write from file to another file lines that do not start with defined charachter so i can enter that character into parameters or..?


           try {
                File input = new File("input");
                File output = new File("output");
                Scanner sc = new Scanner(input);
                PrintWriter printer = new PrintWriter(output);
                while (sc.hasNextLine()) {
                    String s = sc.nextLine();
                    printer.write(s);
                }
                printer.flush();
            }
            catch (FileNotFoundException e) {
                System.err.println("File not found. Please scan in new file.");
            }


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    589
    My Mood
    Sleepy
    Thanks
    10
    Thanked 87 Times in 80 Posts

    Default Re: write lines which start without cahracter

    No, but it's a plain if statement checking the first char of the line. Check the String API doc for useful methods.

Similar Threads

  1. Replies: 15
    Last Post: May 2nd, 2013, 05:29 AM
  2. Not sure where to start: Trying to write a program dealing with an Amazon API
    By ~DrummerGirl~ in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 19th, 2013, 06:20 PM
  3. Write to New lines in a file
    By ganapathi in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 10th, 2013, 10:28 AM
  4. Help with three lines
    By heythisgreg in forum Java Theory & Questions
    Replies: 9
    Last Post: February 17th, 2013, 04:40 PM