Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java Create a file that contains your favorite movie quote
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


bob
Java Create a file that contains your favorite movie quote
1 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


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.


Advertisement
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
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
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
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
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
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
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
youtube movie
youtube movie  how to get you tube movie in java please help me for code thanks in advance raman
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
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
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 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
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
Adding slash "\" character before quote "'" in a query
before the quote. For example if the user enters "What's your name?" then we... in your java application to add the slashes. public String addSlashes... Adding slash "\" character before quote "'"
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
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 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
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
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 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... createNewFile(), you can create a file. Output: File is created
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
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
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
Movie clip in flex
Movie clip in flex  Hi... What is a MovieClip? IUIMovieClip? please... direct any movie clip to stop, play, or go to another point on the timeline, it cannot be used to dynamically create a timeline or add content at specific
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
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
Create Tag Library Descriptor (TLD) File
, we learn how to create library descriptor file in your project. Developers can... Create Tag Library Descriptor (TLD) File  ... these steps to create the file:   1. Go to project option and right click
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
Advertisements
 

 

 

DMCA.com