 2007 West |
|
GOLD SPONSORS:
|
Active Endpoints Your SOA Needs BPEL for Orchestration
|
BEA Virtualized SOA: Adaptive Infrastructure for Demanding Applications
|
Nexaweb Overcoming Bandwidth Challenges with Nexaweb
|
TIBCO What is Service Virtualization?
|
|
SILVER SPONSORS:
|
WSO2 Using Web Services Technologies and FOSS Solutions
|
|
Click For 2007 East Event Webcasts
|
|
TOP THREE LINKS YOU MUST CLICK ON
Java Basics
Java Streams Basics
This installment has Yakov looking at Java Streams Basics.
Reader Feedback : Page 1 of 1
#13 |
Frederik De Milde commented on the 6 Feb 2005
A little bug in your code snippet on Buffering: buff shouldn't be declared twice... FileInputStream myFile = null; BufferedInputStream buff =null try { myFile = new FileInputStream("abc.dat"); BufferedInputStream buff = new BufferedInputStream(myFile); boolean eof = false; while (!eof) { int byteValue = buff.read(); System.out.print(byteValue + " "); if (byteValue == -1) eof = true; } } catch (IOException e) { e.printStackTrace(); } finally{ buff.close(); myFile.close(); } |
#12 |
Muiris O Cleirigh commented on the 29 Mar 2004
There seems to be a problem rendering this article - this part doesn''t make a lot of sense to me ...... The next code fragment writes into the file xyz.dat using the class FileOutputStream: int somedata[]={56,230,123,43,11,37}; FileOutputStream myFile = null; try { myFile = new FileOutputStream("xyz.dat"); for (int i = 0; i You can use stream chaining (or stream piping) to connect streams - think of connecting two pipes in plumbing. Let''s modify the example that reads the file abc.dat to introduce the buffering:
FileInputStream myFile = null; BufferedInputStream buff =null try { myFile = new FileInputStream("abc.dat"); BufferedInputStream buff = new BufferedInputStream(myFile); boolean eof = false; while (!eof) { int byteValue = buff.read(); System.out.print(byteValue + " "); if (byteValue == -1) eof = true; } } catch (IOException e) { e.printStackTrace(); } finally{ buff.close(); myFile.close(); } |
#11 |
Excellent article. This has got to be one of the best Stream tutorials out there. I''m also very impressed with your coverage of the StreamTokenizer -- this is an "esoteric" class that few people know and understand how to use effectively. I''m also very impressed with a nice concise run-down of the File class features, such as directory management. Again, excellent article. Keep up the good work! Greg |
#10 |
michael turner commented on the 7 Jan 2004
This was a good summarization of Java Stream Basics. I have retained sections of the article for Reference. Thank you for presenting the information |
#9 |
Sorry, the FileReader should have been closed: import java.io.StreamTokenizer; import java.io.FileReader; public class CustomerTokenizer{ public static void main(String args[]){ StreamTokenizer stream =null; FileReader fr=null; try{ fr = new FileReader("customers.txt"); stream = new StreamTokenizer(fr ); while (true) { int token = stream.nextToken(); if (token == StreamTokenizer.TT_EOF) break; if (token == StreamTokenizer.TT_WORD) { System.out.println("Got the string: " + stream.sval); } if (token == StreamTokenizer.TT_NUMBER) { System.out.println("Got the number: " + stream.nval); } } }catch (Exception e){ System.out.println("Can''t read Customers.txt: " + e.toString()); } finally{ try{ fr.close(); }catch(Exception e){e.printStackTrace();} } } } |
#8 |
thomas harris commented on the 7 Jan 2004
I tried to compile the CustomerTokenizer class and came up with the following error: File: C:\java\test\CustomerTokenizer.java [line: 33] Error: cannot resolve symbol symbol : method close () location: class java.io.StreamTokenizer I checked the api, and the close() method is available via java.io.FileReader so I am not clear on why I got the above error message. Is the compiler looking for the method in the wrong class? |
#7 |
One of ther readers asked me the questions listed below, and I decided to publish the answers over here as well. What is the reason for a buffered reader and buffered writer--what is the need for buffering? Buffering allows you to read a bunch of bytes from disk into the buffer in one shot, and then the program gets the data from the buffer from the memory byte by byte, int by int, etc. This minimizes the number of times your program has to access the disk. StreamTokenizer does not have a close method. How do you close a Stream Tokenizer? The StreamTokenizer is not a stream itself - it does not need to be closed. |
#6 |
Andrey Postoyanets commented on the 6 Jan 2004
So far the style of this lessons series has been outstanding. Nothing can be more valuable than informative, easy-to-follow examples with a clear explanation. I also agree that the usage of Java streams and XML manipulation would be a great topic for one of the future articles. |
#5 |
Matt Campbell commented on the 6 Jan 2004
LOL! |
#4 |
Steve Krenz commented on the 6 Jan 2004
What''s VB ;-) |
#3 |
Matt Campbell commented on the 6 Jan 2004
You know, it still isn''t nearly as easy as getting a stream of chars by line or a whole file for parsing as it is in VB. :) |
#2 |
Steven Krenz commented on the 6 Jan 2004
Good article as far as it goes but what would be much more helpful would be a discussion of how readers differ from and are built on streams. What I always find difficult to remember is the best way to read a whole line of data from a stream and not just characters. The connection between java.io streams and org.xml.sax.InputStream is what I suspect most developers are concerned about right now. |
#1 |
Warawich Sundarabhaka commented on the 5 Jan 2004
very good lesson and example. |
YOUR FEEDBACK  | Is Sun Looking to Replace
CEO Jonathan Schwartz? By Maureen O'Gara Brigdson Smith wrote:
remember, Eric Schmidt
was Schwartz's first boss
at Sun - something tells
me if he left Sun, it'd
take four minutes for him
to end up to Google. |  | What Does the Future Hold
for the Java Language? By Joe Winchester Tommy wrote: I simply do
not agree on many parts:
- .NET has a lot of
traction
- you can
certainly know well (and
master) more than one
language. If you cannot
master more than one
language, this could
potentially be one of
your limits.
- Java is not a perfect
language
- It is ea... |  | i-Technology Opinion: Why
Use Extreme Programming? By Troy Holmes James Nwaba wrote: This
is a nice article - very
straight froward, easy to
understand.However, there
was no mention of any
organization that have
implemented XP.
The author said, "Many of
the concepts found in
this lightweight method
of development have been
implemented into the ... |  | iPhone Office: 100 Ways
to Turn Your Device into
the Ultimate Productivity
Tool By Jessica Merritt QueZZtion wrote: Can the
iPhone really work as a
multimedia remote for
iTunes or even a desktop? |  | DoJa in NTT DoCoMo Phones By Zev Blut Venkat wrote: Excellent
explanation. It will be
helpful if it was in
pictorial form ie with
the emulator images. Can
u please send me the
I-mode to I appli
communication and a brief
explanatioj about the
architecture.Thanks in
advance. |
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
|
SYS-CON FEATURED WHITEPAPERS  | Saving Your Investment:
Transforming J2EE
applications into Web 2.0
using GWT By RIA News Desk The pressure is on to
keep pace with Web 2.0
entrants into the
marketplace. Rewriting is
expensive; | WSRP Really Works! - Part
2 By Matt Silver A standard from OASIS
called Web Services for
Remote Portlets (WSRP) is
used so portlets can be
deco | Adobe's Kevin Lynch and
Microsoft's Scott Guthrie
to Keynote AJAX World RIA
Conference & Expo By RIA News Desk Two of the biggest
launches in Rich Internet
Application history took
place in 2007/2008 when
Adobe | Sun Expects Q4 Earnings
Above Estimates By Java News Desk On Tuesday evening Sun
issued a fourth-quarter
guidance range largely
above analysts'
estimates. The | Virtualization Conference
Keynote Webcast Live on
SYS-CON.TV By James Hamilton Brian Stevens, the Chief
Technology Officer and
Vice President of
Engineering of Red Hat,
delivered | The Beauty of JavaScript By RIA News Desk JavaScript is one of the
most interesting and
misunderstood programming
languages in common use
toda | JavaScript: The Good
Parts By RIA News Desk JavaScript is a language
with more than its share
of bad parts. It went
from non-existence to
global | Use JavaScript 2 Today
with OpenLaszlo By RIA News Desk JavaScript 2 is becoming
increasingly important.
Learn how to take
advantage of JavaScript 2
while s | Server-Side JavaScript -
All the Cool Kids Are
Doing It! By RIA News Desk In this session that no
developer who uses
JavaScript or
ActionScript will want to
miss, delegates w | AJAX with jQuery By RIA News Desk jQuery is a rapidly
growing, popular
JavaScript library. Its
powerful and modular
architecture, whic | Why the Web Dinosaurs
Died By Jonas Jacobi; John Fallows; Ric Smith; Brian Albers A fast-moving Comet is
about to impact the
Internet. When it hits,
it will wipe away the
architectur | Sun Achieves Land Speed
Record: 1M Messages Per
Second By Java News Desk Algorithmic trading
continues to drive the
quest for greater speed
and lower latency in the
capital | AJAX and RIA Technology
Will Be Free for All: Sun
CEO By Java News 'Java's always been a RIA
platform - before the
world really wanted one,'
claimed Sun's CEO
Jonathan | Quest Software's JProbe
Now Available as Eclipse
Plug-In By Eclipse News Desk Quest Software announced
the latest release of its
Java profiler, JProbe
8.0, which is now offered
a | What Does the Future Hold
for the Java Language? By Joe Winchester Before Java I was a
Smalltalk guy. I remember
switching from one
language to the other and
the tippi | White Paper: "Ensuring
Code Quality in
Multi-Threaded
Applications" By Java News Desk Today, the world of
software development is
presented with a new
challenge. To fully
leverage this n | AccuRev and Rally
Software Partner to Scale
Agile Software
Development Best
Practices By SOA World Magazine News Desk AccuRev and Rally
announced a technology
partnership that will
integrate AccuRev
software change and | MyEclipse 6.5: The Maven
Tipping Point for 1
Million Java Developers By Eclipse News Desk Genuitec announced the
availability of MyEclipse
Enterprise Workbench 6.5;
Java's most compelling ID | AccuRev Leverages Web 2.0
Technology to Extend
Process Management Reach
Across the Organization By Web 2.0 News Desk AccuRev announced a new
AJAX-based Web Interface
and a native integration
with Microsoft Windows
Exp | Voyager Offers Android,
.NET CF, Java Runtime
Support By Wireless News Desk Recursion Software
released a private beta
version of their Voyager
mobile platform, with
powerful i |
SPONSORED BY INFRAGISTICS
|