Java Create a file that contains your favorite movie quote

Java Create a file that contains your favorite movie quote

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 FileStatistics2.java.

View Answers

June 19, 2012 at 11:56 AM

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.

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){}
     }
    }

Ads









Related Tutorials/Questions & Answers:
Java Create a file that contains your favorite movie quote
Java Create a file that contains your favorite movie quote  Create a file that contains your favorite movie quote. Use a text editor such as Notepad... the user to enter the favorite movie quote. Then write it into the text file and Copy
Create an HTML file AddCookies.html which contains four text boxes
Create an HTML file AddCookies.html which contains four text boxes  Create an HTML file AddCookies.html which contains four text boxes .When user enters the values in these text boxes and press the submit button, the values
Advertisements
ModuleNotFoundError: No module named 'movie-file-fixer'
named 'movie-file-fixer' How to remove the ModuleNotFoundError: No module named 'movie-file-fixer' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'movie-file-fixer'  Hi, My
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  ... format but I am unable to do it. For example word document contains name [CutomerName] Address [Cs_add] This is my template file. I want
Create File in Java
CreateFile1.java C:\nisha>java CreateFile1 New file "myfile.txt" has... Create a File        Introduction Whenever the data is need to be stored, a file is used
Create new file in java
Create new file in java We are going to discuss how to create new file in java.... With File class we create files and directories. Java File represents actual... create main method than we use try and catch block. We have created File object
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
create table in mysql of split file created in java
create table in mysql of split file created in java  i have created splite file in java. now i want to create table from splited data how to do
Java to create table in jsp file that include other jsp file
Java to create table in jsp file that include other jsp file  String jspContent = "table" += "tr" += "td" += "jsp:include page='fileSource... this http://www.roseindia.net/tutorial/java/core/files/javacreatetableinHTML.html
Create File in Java
of how to create a file in java: package FileHandling; import java.io.File...File is nothing but a simple storage of data in Java language. We call one... and text data to the file. The File.createNewFile() method is used to create
Create your own Notepad in Java
Create your own Notepad in Java           You must have worked with Notepad to write programs. Now its turn to create notepad by own with the help of java language
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... the favorite movie quote. Then write it into the text file and Copy the file contents
How To Create a New File
store String, characters, numbers etc. In Java to create a File for storing... which will demonstrate you about how to create a new file in Java...How To Create a New File In this section we will discuss about how to create
Java Swing Create XML file
Java Swing Create XML file In this tutorial, you will learn how to create XML file using swings. Here is a code that accepts the data from the user through... and fetch all the data from textfields and create an xml file with proper
How to create a jar file
???   The given code creates a jar file using java. import java.io.*; import...How to create a jar file  Hello!!!! I have a project which has...; protected void createJarArchive(File jarFile, File[] listFiles) { try
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
we can create our own header file in java?n how to create?
we can create our own header file in java?n how to create?  we can create our own header file in java?n how to create
how to create a set up file of java web application
how to create a set up file of java web application  I have already developed a java web application using struts 2.x, jsp, oracle as a back end data... if any one knows how to do the java web application as a set up file, please help
how to create a set up file of java web application
how to create a set up file of java web application  I have already developed a java web application using struts 2.x, jsp, oracle as a back end data... if any one knows how to do the java web application as a set up file, please help
how to create a set up file of java web application
how to create a set up file of java web application  I have already developed a java web application using struts 2.x, jsp,tomcat server, oracle... to my client, so in this case I would like to make my product as a setup file,where
Create zip file in Java
Create zip file in Java     .... You will also learn how to create a zip file from any file through the java... applications. This program shows you how to zip any file through your java
Example of contains method of hashset in java.
Example of contains method of hashset in java. The contains() is a method of hashset. It is used for checking that the given number is available..., it returns true otherwise false. Code:  HashSetToArray .java
Java Objectives Question
as FileStatistics.java. Exercise 2: Create a file that contains your favorite movie quote. Use...Java Objectives Question  Exercise 1: Create a file by using any word... that contains the name of the user's favorite book and then displays it to the user
Online Radio Applications ? Listen To All Your Favorite Songs On The Go
Online Radio Applications – Listen To All Your Favorite Songs On The Go... and listen to your favorite songs wherever you are. The downside was still carrying... for a while but still want to stay in touch with your favorite stations back home
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
youtube movie
youtube movie  how to get you tube movie in java please help me for code thanks in advance raman
How to check if an arraylist contains a value in Java
How to check if an arraylist contains a value in Java  Hi, I have an array list object in Java with few values. I want to check if it contains... to do this? How to check if an arraylist contains a value in Java? Thanks  

Ads