• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

copying one .doc file to another

 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic