I\'ll vote best answer with five stars for the most simple and direct response t
ID: 3549155 • Letter: I
Question
I'll vote best answer with five stars for the most simple and direct response that solves the problem at hand. Please don't submit run-ons or irrelevant answers.
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 console application that displays the sizes of the two files as well as the ratio of their sizes to each other. To discover a file's size, you can create a System.IO.FileInfo object using a statement such as the following, where FILE_NAME is a string that contains the name of the file:
Thanks.
Explanation / Answer
import java.io.*;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){try{POIFSFileSystem fs = new POIFSFileSystem();DirectoryEntry directory = fs.getRoot(); directory.createDocument("WordDocument", new ByteArrayInputStream(content.getBytes()));FileOutputStream out = new FileOutputStream(path); fs.writeFilesystem(out);out.close();}catch(Exception ex) {System.out.println(ex.getMessage());}}public static void main(String[] args) {File f=new File("c:/Quote.txt");try{Scanner input=new Scanner(System.in);System.out.println("Enter fav movie quote: ");String str=input.nextLine();BufferedWriter bw=new BufferedWriter(new FileWriter(f,true)); bw.write(str); bw.newLine(); bw.close();BufferedReader br=new BufferedReader(new FileReader(f));String s="",st="";while((s=br.readLine())!=null){ st+=s+" ";}File file=new File("c:/Quote.doc"); writeToFile(str,file.getPath());System.out.println("Text File Size: "+f.length());System.out.println("Word File Size: "+file.length());}catch(Exception e){}}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.