Raven Mad Libtxt Once upon a timeofday dreary while I word w
Raven Mad Lib.txt
Once upon a (timeofday) dreary, while I (word), weak and weary,
Over many a quaint and curious (noun) of forgotten lore—
While I nodded, nearly napping, suddenly there came a (verb),
As of some one gently rapping, rapping at my chamber (noun) .
“’Tis some (noun) ,” I muttered, “tapping at my chamber door—
Only this and nothing more.”
The Farm Mad Lib.txt
I spent last summer on my grandfather\'s (adjective) farm. He
raises oats, wheat, and (noun) . Grandfather also grows lettuce,
corn, and lima (pluralNoun) . My favorite place to (verb) on
the farm is the (noun) house where Grandfather keeps his
(adjective) chickens. Every day, each hen lays round, smooth
(pluralNoun) . Grandfather sells most of them, but keeps some so
the hens can (verb) on them and hatch cute, fuzzy little
(pluralNoun) for an hour, and climb a (noun).without losing your
(partofBody) . I\'m looking forward to next year, when Grandfather
is going to show me how to drive his (noun) , sow the
(noun) , and (verb) the cow.
Solution
Program:
import java.io.*;
import java.util.Scanner;
public class Replacement {
public static void main(String args[]) throws IOException {
int i;
FileInputStream fin;
FileOutputStream fout;
BufferedReader reader = null;
FileWriter fw=null;
BufferedWriter bw=null;
Scanner s=new Scanner(System.in);
try {
// open input file
try {
System.out.print(\"Please Type In the Name Of The File : \");
fin = new FileInputStream(s.nextLine());
reader = new BufferedReader(new InputStreamReader(fin));
} catch (FileNotFoundException e) {
System.out.println(\"Input File Not Found\");
return;
}
// open output file
try {
System.out.print(\"Please Type In the Name Of The Output File : \");
File f = new File(s.nextLine());
fw = new FileWriter(f);
bw = new BufferedWriter(fw);
} catch (FileNotFoundException e) {
System.out.println(\"Error Opening Output File\");
return;
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(\"Usage: CopyFile From To\");
return;
}
// Copy File
try {
String line = reader.readLine();
while(line != null){
if(line.contains(\"(\"))
{
String split[]=line.split(\" \");
for(int j=0;j<split.length;j++)
{
String val=split[j];
if(val.startsWith(\"(\") && val.endsWith(\"\"))
{
System.out.print(\"While Reading Your File I have found \"+val+\" please type in the replacement :\");
String newValue=s.nextLine();
bw.write(newValue);
bw.write(\" \");
}
else
{
bw.write(val);
bw.write(\" \");
}
}
}
//System.out.println(line);
line = reader.readLine();
}
System.out.println(\"Your File Is Done\");
/*do {
i = fin.read();
if (i != -1)
fout.write(i);
} while (i != -1);*/
} catch (IOException e) {
System.out.println(\"File Error\");
}
fin.close();
bw.flush();
bw.close();
}
}

