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









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
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
How to create a new text file that contains the file names of the copied files in a new directory?  Okay so my question is: How to create a new text file that contains the file names of the copied files in a new directory
Advertisements
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
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
movie class..(dr java) - Java Beginners
movie class..(dr java)  hi there.....am about to create a movie class.... but need to declare the name of movie , name of director of movie...)); list.add(new movie("Bhoot","Ram Gopal Verma",false)); File file = new File("C
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
Movie and Cinema class - Java Beginners
Movie and Cinema class  Hi, I'm new in java. Can someone help me...: Question: 1. Create a new Movie class which has two properties, title... the family members. Next create a new movie and use it to set the movie property
Create File in Java
:\nisha>java CreateFile1 The specified file is already exist C... Create a File        Introduction Whenever the data is need to be stored, a file is used
Create JAR file - Java Beginners
Create JAR file  Respected Sir, I got the answer from your side. But do let me know, isn't there any other way of making a JAR File. Simply like... each time in order to run your JAVA program on some other computer, it;s better
CREATE AND WRITE FILE THREAD JAVA
CREATE AND WRITE FILE THREAD JAVA  Hi guys I was wondering how can I make this program in java with threads. I need to create a file and write in it (i know how to do that) but by listening in some port all the data that is being
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
Java file create new file
Java file create new file This section demonstrates you how to create a new... of these tools, you can can easily create a new empty file. Now for this task, we have..."); } } } Through the method createNewFile(), you can create a file. Output
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
how can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format... that you want to create a JAR file. * The f option indicates that you want
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 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
_TO_REPLACE_1 Example of how to create a file in java: package FileHandling; import...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
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
Need to push the combo box to flash movie - Java Beginners
Need to push the combo box to flash movie   Hi, I need to push the combo box values to the flash movie. I am succusfull in pushing the textfield using some pushand getMovie methods in java scripts and HTML[here we enter
How To Create a New File
How To Create a New File In this section we will discuss about how to create a new file in Java. A Computer File is a storage of data. In this file we can store String, characters, numbers etc. In Java to create a File for storing
youtube movie
youtube movie  how to get you tube movie in java please help me for code thanks in advance raman
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
Java create table in html file
Java create table in html file In this section, you will learn how to create table in html file. In the previous section, you have seen different operations... as an argument. Now we have used the html table tag to create a table in html file
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
Create and Show Wordpad File on JButton Click - Java Beginners
Create and Show Wordpad File on JButton Click  Hello Sir I want to create wordpad or word document on JButton Click Event.which contains data which..."); JOptionPane.showMessageDialog(null,"Inserted into File
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
how to create a jar file for java classes? - Java Interview Questions
how to create a jar file for java classes?  I have 2 classes x1 and x2. packages names are com.bank.xyz; how to create a jar file for classes...://www.roseindia.net/tutorial/java/io/createJarFile.html Hope that it will be helpful
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
how to create .exe file of java application?? - Java Beginners
how to create .exe file of java application??  hi i want to know how to create exe file of whole application so that i can use that application... createJarArchive(File jarFile, File[] listFiles) { try { byte b
Java MappedByteBuffer example, How to create a large size file in java.
Java MappedByteBuffer example, How to create a large file in java. In this tutorial, you will see how to create a large file with the help...;} } Output C:\>java CreateFile File
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
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
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
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
ModuleNotFoundError: No module named 'movie'
ModuleNotFoundError: No module named 'movie'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'movie' How to remove the ModuleNotFoundError: No module named 'movie'
ModuleNotFoundError: No module named 'quote'
ModuleNotFoundError: No module named 'quote'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'quote' How to remove the ModuleNotFoundError: No module named 'quote'
Show Time Maps
Show Time Maps       Quickly find and compare movie times at your favorite theaters through a map-based interface. While in beta, we are serving only Los Angeles and Austin markets
Java file create temp file
Java file create temp file This section illustrates you how to generate a temporary file. Description of code: A temporary file stores information temporarily to free the memory for other purposes. You can use this temporary file
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
FTP Server : Upload file
This tutorial contains description of file uploading to the FTP server using java
How to Create Jar File using Java
How to Create Jar File using Java Programming Language A Jar file combines... in the jar file.  In this section, we are going to create our own jar file... is to be combined and the path of jar file where we want to create the jar file. Here
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  
How to create XML file - XML
creating your file save it with .xml extension.  Hi,Java programming...()); }}Thanks  Hi,Java programming language has many API's to create xml file from...How to create XML file  Creating a XML file, need an example. Thanks

Ads