Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

buffer stream

 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can some one tell me is this statement legal ? DataOutputStream dos = new DataOutputStream(new BufferOutputStream(new FileOutputStream));

i checked and i found that there are only one constructor for DataOutputStream which is -> DataOutputStream(FileOutputStream xx)
some correct me please~ thanks in advanced.


 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the what is the intend of using buffer stream in dataoutput? for speed up the performance?
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can some one tell me is this statement legal ? DataOutputStream dos = new DataOutputStream(new BufferOutputStream(new FileOutputStream));

What happened when you tried to compile it?

i checked and i found that there are only one constructor for DataOutputStream which is -> DataOutputStream(FileOutputStream xx)

The place to check is the API docs. Google "Java XXX API Docs" where XXX is whatever version of Java you are using
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the what is the intend of using buffer stream in dataoutput? for speed up the performance?

Again check the API docs.
Using a stream buffer can improve performance depending on what and where the stream source is and how you are using it but they may also provide additional features such as BufferedInputStream which adds the mark and reset feature.
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try the statement and it works.

this is the api i found http://docs.oracle.com/javase/6/docs/api/java/io/DataOutputStream.html

it dint state the constructor for bufferstream
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it dint state the constructor for bufferstream

It also doesn't have a constructor for FileOutputStream as your first post stated. It does, however, have a constructor for OutputStream, so any class that is a sub class of OutputStream such as BufferedOutputStream can be passed in.
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh shit!!! careless,thanks ^^
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:
it dint state the constructor for bufferstream

It also doesn't have a constructor for FileOutputStream as your first post stated. It does, however, have a constructor for OutputStream, so any class that is a sub class of OutputStream such as BufferedOutputStream can be passed in.


1 more question.....how i dint invoke the close method after finished the work?
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 more question.....how i dint invoke the close method after finished the work?

Sorry, I don't understand your question. Can you try asking again.
 
kahkean chor
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
usually we will invoke the close method

try{}
catch{}
finally{ datainputstream.CLOSE()}

what will happened if we dint invoke this method?thanks for your patient
 
Tony Docherty
Saloon Keeper
Posts: 3145
74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no CLOSE() method but there is one called close() which I assume you mean.

If you don't close the stream it will remain open and may continue to hold system resources. Also if you haven't called flush() after the last write some of the data you have written may not be flushed from the stream and may be lost when your application closes.
 
Space pants. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!