Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

File IO

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Chicken Farmer ()
Posts: 1932
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic