Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2008

Tip: Looking for answers? Try searching our database.

File I/O Advice needed....

Thread view: 
TheBigPJ - 05 Mar 2008 00:14 GMT
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
Thank you.

Peter


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.