The following code creates one file at a time by reading jokes from an array. But I'm trying to have it read in from a text file 5-10 jokes, and then create 3 files at the same time (dat, byte and object type). Help me please.
import java.util.*;
import java.io.*;
public class Joking
{
static final String dataFile = "OldByte.obj ";
static final String[] jokes = {"Chuck Norris could use anything in java.util.* to kill you, including the javadocs.", "If you get a ChuckNorrisException you’ll probably die.", "Chuck Norris doesn't travel at the speed of light, light travels at the speed of Chuck Norris!", "Chuck Norris can make a class that is both abstract and final.", "Every single line code of Chuck Norris runs in real time. Even in a multi threading application.", "Chuck Norris doesn’t write code. He stares at a computer screen until he gets the program he wants.", "Chuck Norris methods don’t catch exceptions because no one has the guts to throw any at them."};
public static void main(String[] args) throws IOException
{
/*
Scanner scanner = new Scanner(new FileRead("jokes.txt"));
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
System.out.println(line);
}
*/
DataOutputStream outDat = null;
//DataOutputStream outTxt = null;
//DataOutputStream outObj = null;
try
{
outDat = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile)));
//outTxt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile)));
//outObj = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(dataFile)));
for (int i = 0; i < jokes.length; i++)
{
outDat.writeUTF(jokes[i]);
//outTxt.writeUTF(jokes[i]);
//outObj.writeUTF(jokes[i]);
}
}
finally
{
outDat.close();
}
}
}
This post has been edited by asdbabil: 03 March 2010 - 06:28 PM

New Topic/Question
Reply



MultiQuote








|