This discussion is archived
6 Replies Latest reply: Mar 25, 2008 12:44 PM by 807601 RSS

Need help in text file reading and saving to another..

807601 Newbie
Currently Being Moderated
Hello,
I have design a method work like a language stemmer called root "this will give you the original word without any additional prefixes or suffixes..
Now I have two text files, the first text will be the input file containing some words, and the second will be the output file contains the stemmed words..
My problem is in connecting the two files, i need a code in main method that reads the input file and write the output to another file using the method "root"..

see this code"the problem, to explain my question only" and tell me what is the write way to do it please:

{code}public static void main(String[] args) throws Exception{

Scanner freader = new Scanner("d:\\input.txt");
BufferedWriter writer = new BufferedWriter(new FileWriter("d:\\output.txt"));


String line = null;
while (freader.hasNextLine()) {
line = freader.nextLine();
writer.println(root(freader.next()));
}

//... Close reader and writer.
freader.close(); // Close to unlock.
writer.close(); // Close to unlock and flush to disk.
}{code}

thank you,

Edited by: realahmed8 on Mar 25, 2008 6:02 AM

Edited by: realahmed8 on Mar 25, 2008 6:04 AM
  • 1. Re: Need help in text file reading and saving to another..
    807601 Newbie
    Currently Being Moderated
    why don't use pass 'line' to root? Also, what are you asking?
  • 2. Re: Need help in text file reading and saving to another..
    807601 Newbie
    Currently Being Moderated
    "newark", please forget the code written i have said its not right and thats what iam asking about..
    i wanna help in writting a java code that connects my 2 files input.txt , output.txt using a method called "root"
    Now, Simply :
    I have two files available.. the first file "input.txt" contains some words and statements..
    the second file "output.txt" is empty now, and should contain the stemmed of words
    and statements available in "input.txt" when i run the code..
    **Note: the "root" method stemm words and statements.
  • 3. Re: Need help in text file reading and saving to another..
    807601 Newbie
    Currently Being Moderated
    please help me if you can.. i need this help too much
  • 4. Re: Need help in text file reading and saving to another..
    807601 Newbie
    Currently Being Moderated
    stemm words? stemmed words? What are these?
  • 5. Re: Need help in text file reading and saving to another..
    DrClap Expert
    Currently Being Moderated
    The "stem" of a word is the basic part of the word, with grammatical doohickeys cut off. For example, "dog" is the stem for "dogs" and "eat" is the stem for "eating".

    I have no idea what to say to the OP. I can't tell whether he doesn't know how to read from a file and write to a file, or whether he doesn't know how to write a method, or whether he doesn't know how to do this stemming thing. And the only code example we have is one that is irrelevant.

    Let's try this: [Java I/O tutorial|http://java.sun.com/docs/books/tutorial/essential/io/]

    If that isn't the answer, then we need a question.
  • 6. Re: Need help in text file reading and saving to another..
    807601 Newbie
    Currently Being Moderated
    again, the question is:
    how can i use the method i have implement"calle root" to write a file..
    see this sample "it still logically wrong" but for explain my idea:
    public static void main(String[] args) throws Exception{
            
           File output = new File("output.txt");
           System.out.println("please: Enter the path of input file");
           Scanner a=new Scanner(System.in);
           String path=a.next();
           
           File input = new File(path);
           
           PrintWriter pw=new PrintWriter (output);
           for(int i=0;i<200;i++){
               while (a.hasNext()){
                  
           
           pw.println(*root*(a.next()));
           
               }       
           }
    note the word "root" its my method..