
Exercise 1: Create a file by using any word-processing program or text editor. Write an application that displays the file's name, size, and time of last modification. Save the file as FileStatistics.java.
Exercise 2: 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.
Exercise 3: Write an application using the FileInputStream that opens a file that contains the name of the user's favorite book and then displays it to the user. If the file does not exist, prompt the user for the book's title and then write it to the file by using a FileOutputStream. Save the file as DisplayBook.java.

Exercise 1:
Here we have created a text file and display its name, size and last modification date & time.
import java.io.*;
import java.util.*;
import java.text.*;
class FileStatistics{
public static void main(String[] args){
try{
File f=new File("c:/data.txt");
BufferedWriter bw=new BufferedWriter(new FileWriter(f));
bw.write("Hello World!");
bw.close();
String name=f.getName();
long len=f.length();
long lastModified=f.lastModified();
System.out.println("File Name: "+name);
System.out.println("File Sie: "+len);
Date d=new Date(lastModified);
SimpleDateFormat sdf=new SimpleDateFormat("dd-MM-yyyy hh:mm");
System.out.println("File Last Modified: "+sdf.format(d));
}
catch(Exception e){
}
}
}

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

On number 2 I'm getting this errors
FileStatistics2.java:3: error: package org.apache.poi.hwpf does not exist import org.apache.poi.hwpf.HWPFDocument; ^ FileStatistics2.java:4: error: package org.apache.poi.hwpf.usermodel does not exist import org.apache.poi.hwpf.usermodel.*; ^ FileStatistics2.java:5: error: package org.apache.poi.hwpf.usermodel does not exist import org.apache.poi.hwpf.usermodel.Range; ^ FileStatistics2.java:6: error: package org.apache.poi.poifs.filesystem does not exist import org.apache.poi.poifs.filesystem.*; ^ FileStatistics2.java:7: error: package org.apache.poi.hwpf.extractor does not exist import org.apache.poi.hwpf.extractor.WordExtractor; ^ FileStatistics2.java:13: error: cannot find symbol POIFSFileSystem fs = new POIFSFileSystem(); ^ symbol: class POIFSFileSystem location: class FileStatistics2 FileStatistics2.java:13: error: cannot find symbol POIFSFileSystem fs = new POIFSFileSystem(); ^ symbol: class POIFSFileSystem location: class FileStatistics2 FileStatistics2.java:14: error: cannot find symbol DirectoryEntry directory = fs.getRoot(); ^ symbol: class DirectoryEntry location: class FileStatistics2 8 errors
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.