Java Question Anyone need some HELP !!

Java Question Anyone need some HELP !!

Create a file that contains your favorite movie quote. Use a text editor such as Notepad and save the file as Quote.txt. Copy the file contents and paste them into a word-processing program such as Word. Save the file as Quote.doc. Write an application that displays the sizes of the two files, as well as the ratio of the two file sizes. Save the file as

View Answers

July 3, 2012 at 1:24 PM

Here, we have created a text editor such as Notepad and save the file as Quote.txt and ask the user to enter the favorite movie quote. Then write it into the text file and Copy the file contents and save them into a word file 'Quote.doc'. After that, we have displayed the sizes of the two files.

Note: For the above code, you need POI api.

import java.util.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.hwpf.usermodel.Range;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hwpf.extractor.WordExtractor;

class FileStatistics2
    static void writeToFile(String content, String path){
        POIFSFileSystem fs = new POIFSFileSystem();
        DirectoryEntry directory = fs.getRoot();
        directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));
        FileOutputStream out = new FileOutputStream(path);
        catch(Exception ex) {
    public static void main(String[] args) 
        File f=new File("c:/Quote.txt");

        Scanner input=new Scanner(;
        System.out.println("Enter fav movie quote: ");
        String str=input.nextLine();
        BufferedWriter bw=new BufferedWriter(new FileWriter(f,true));


        BufferedReader br=new BufferedReader(new FileReader(f));
        String s="",st="";
            st+=s+" ";
        File file=new File("c:/Quote.doc");
             System.out.println("Text File Size: "+f.length());
             System.out.println("Word File Size: "+file.length());

        catch(Exception e){}

July 3, 2012 at 2:54 PM

Download zip file from the following link:

Then put the poi-3.2-FINAL-20081019.jar,poi-contrib-3.2-FINAL-20081019.jar and poi-scratchpad-3.2-FINAL-20081019.jar files into the following path:



Related Tutorials/Questions & Answers: