This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

copying one .doc file to another  RSS feed

 
sitaram irrinki
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import java.util.*;
public class Wdadta {

/** Creates a new instance of Wdadta */
public Wdadta() {
}
public static void main(String args[])throws Exception
{
FileReader fr=new FileReader("c:\\java\\cv.doc");
FileWriter fw=new FileWriter("c:\\java\\cv1.doc");
char ch;
int i;
String str="";
while((i=fr.read())!=-1)
{
ch=(char)i;
if(ch!='\n')
{
str=str+ch;
}

else
{
StringTokenizer st=new StringTokenizer(str);
while(st.hasMoreTokens())
{
String f=st.nextToken();
f.trim();
fw.write(f);
fw.write("\r\n");
}
str="";
}

}
fw.close();
}

}
When I attempting t run the abovre program Unneccessary garbage values are comning.But It IS workin properly in case os text files

the solution for this using Apache POI package.if this is the case pls
tell me how to use Apache POI
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are those doc files Microsoft Word files?

Microsoft Word doc files are not text files, so you cannot read and write them using FileReader and FileWriter.

Look at the following example code for copying one file to another:
Copying One File to Another
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!