Which the latest file i/o mechanism to use?
I know this doesn't matter but I think I have mixed up the version
mechanisms,
Thanks,
Peter
------------------------------------------------
import java.util.Random;
import java.io.*;
public class Goody
{
public static void main(String[] args)
{
Goody a = new Goody();
a.theStart(args[0]);
}
void theStart(String temp)
{
int numbersRequired = Integer.parseInt(temp);
int[] tempNumbers = new int [numbersRequired];
try {
/*FileOutputStream fos = new FileOutputStream ("E:/Temp/
data.text");
for(int i = 0; i < numbersRequired; i++)
new PrintStream(fos).println(new Random().nextInt(214));
fos.close();*/
//The above code also works
PrintWriter out = new PrintWriter(new FileWriter("E:/Temp/
data.text"));
for(int i = 0; i < numbersRequired; i++)
out.println( new Random().nextInt(214));
out.close();
BufferedReader in = new BufferedReader(new FileReader("E:/Temp/
data.text"));
for(int i = 0; i < numbersRequired; i++)
tempNumbers[i] = Integer.parseInt(in.readLine());
in.close();
}
catch(Exception e)
{
}
for(int j = 0; j < numbersRequired; j++)
System.out.println(j + ":" + tempNumbers[j]);
}
}
Eric Sosman - 05 Mar 2008 01:28 GMT
> Which the latest file i/o mechanism to use?
> [...]
The one they're going to invent in 2038.

Signature
Eric Sosman
esosman@ieee-dot-org.invalid
Roedy Green - 05 Mar 2008 08:14 GMT
>Which the latest file i/o mechanism to use?
The oldest were the streams, then the Readers and now nio.
However ,there are times when you still want a stream or a Reader.
To see how to use them see http://mindprod.com/applet/fileio.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 05 Mar 2008 13:04 GMT
>> Which the latest file i/o mechanism to use?
>
> The oldest were the streams, then the Readers and now nio.
NIO is six years old now. Readers/Writers came out in JDK 1.1, so they are
pretty hoary in Java terms. From a contemporary perspective none of the three
are "new" in any relevant sense, and which is the "latest" doesn't figure into
the engineering decision of which to use.

Signature
Lew
TheBigPJ - 05 Mar 2008 20:30 GMT