Results 1 to 3 of 3
  1. #1
    hohey is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Need help extracting words from text file

    Hi all,

    Getting stuck in this java problem.

    I have these sample strings in a text file : goldfish, fish, dish, filter

    and i need to extract them out with letters : "is" and need to print them out in another text file.

    Currently I am able to read the contents of the file but I am not able to print the same it in the new file.


    public class Demo {


    public static void main(String[] args) {
    String filename = "a.txt";

    try {
    FileInputStream fis = new FileInputStream(filename);
    DataInputStream dis = new DataInputStream(fis);
    BufferedReader br = new BufferedReader(new InputStreamReader(dis));
    String strLine = null;
    while ((strLine = br.readLine()) != null) {
    System.out.println(strLine);
    FileWriter output = new FileWriter("b.txt");
    BufferedWriter writer =new BufferedWriter(output);
    writer.write(strLine);
    //System.out.println(strLine);
    }

    dis.close();
    } catch (Exception e) {
    e.printStackTrace();
    }

  2. #2
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Need help extracting words from text file

    I use a PrintWriter for file writing. But your problem may be due to the face that you declare and initialize a new filewriter and bufferedwriter for every string. Plus, you never close writer. The term buffered in this case means that the operations you tell the writer to do, will not be done until you close the writer, if you want the buffered writer to act opposite, call writer.flush() after every operation you tell the writer to perform.
    1000011 1100001 1101110 100000 1111001 1101111 1110101 100000 1110010 1100101 1100001 1100100 100000 1000010 1101001 1101110 1100001 1110010 1111001 111111

  3. #3
    hohey is offline Member
    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Default Re: Need help extracting words from text file

    Silly me, able to make some progress. Will keep this thread in case of future issues =D
    Last edited by hohey; 01-24-2014 at 06:04 PM.

Similar Threads

  1. Extracting sentences from a text file
    By warlock in forum New To Java
    Replies: 2
    Last Post: 11-29-2011, 02:22 PM
  2. Extracting values from a text file
    By kryptonian03 in forum New To Java
    Replies: 4
    Last Post: 03-22-2011, 06:13 AM
  3. Extracting and displaying data from a text file
    By fugazi in forum New To Java
    Replies: 4
    Last Post: 01-07-2011, 06:37 PM
  4. Replies: 4
    Last Post: 07-07-2008, 01:32 PM
  5. program help: Extracting words from a string
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 06:39 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
  •