Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File IO  RSS feed

 
Joyce Yu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java File IO system, it doesn't like C that has open() & close() procedures. So if I close an InputStream, how can I open it again. use new? but it wastes time.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"It wastes time?"
I think what you're implying here is that allocating objects using Java "new" is a time-consuming operation. First of all, it's not, not really. Java allocators are pretty sophisticated. Second of all, have your got any idea how many orders of magnitude slower disk I/O is than memory allocation? Allocating an object may take a few hundred cycles, at worst. On a 2GHz processor, this is 100 billionths of a second -- a tenth of a microsecond. Disk seek times are measured in milliseconds; 8 ms is typical. This is enough time to allocate 80,000 objects (somebody might want to check my math!)
Anyway, what I'm saying is, this is a silly question. To open a file, create a FileReader. Use it, close it, make another one if you need to. Don't worry so much about micro performance issues.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I concur with Ernest here. Newing up an object isn't that big of a deal, unless you are newing up a whole heck of a lot of InputStreams, at which point you don't need to worry about processing, you need to worry about your design.
Very few applications I can think of (if any!) are so time dependent that a 10th of a microsecond is a defining factor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!