Java
  Home arrow Java arrow Page 5 - Working with Text Files and File Name Filt...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Working with Text Files and File Name Filters in Java
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-04-27

    Table of Contents:
  • Working with Text Files and File Name Filters in Java
  • Writing Text Files
  • Files and Filename Filters
  • Summary
  • Quiz

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Working with Text Files and File Name Filters in Java - Quiz


    (Page 5 of 5 )

    Review today's material by taking this three-question quiz.

    Questions

    1. What happens when you create a FileOutputStream using a reference to an existing file?

    1. An exception is thrown.

    2. The data you write to the stream are appended to the existing file.

    3. The existing file is replaced with the data you write to the stream.

    1. What two primitive types are interchangeable when you're working with streams?

    1. byte and boolean

    2. char and int

    3. byte and char

    1. In Java, what is the maximum value of a byte variable and the maximum value of an unsigned byte in a stream?

    1. Both are 255

    2. Both are 127

    3. 127 for a byte variable and 255 for an unsigned byte

    Answers

    1. c. That's one of the things to look out for when using output streams; you can easily wipe out existing files.

    2. b. Because a char is represented internally by Java as an integer value, you can often use the two interchangeably in method calls and other statements.

    3. c. The byte primitive data type has values ranging from -128 to 127, whereas an unsigned byte can range from 0 to 255.

    Certification Practice

    The following question is the kind of thing you could expect to be asked on a Java programming certification test. Answer it without looking at today's material or using the Java compiler to test the code.

    Given:

    import java.io.*;
    public class Unknown { public static void main(String[] arguments) { String command = ""; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { command = br.readLine(); } catch (IOException e) { } } }

    Will this program successfully store a line of console input in the String object named command?

    1. Yes.

    2. No, because a buffered input stream is required to read console input.

    3. No, because it won't compile successfully.

    4. No, because it reads more than one line of console input.

    The answer is available on the book's Web site at http://www.java21days.com. Visit the Day 15 page and click the Certification Practice link.

    Exercises

    To extend your knowledge of the subjects covered today, try the following exercises:

    1. Write a modified version of the HexRead program from Day 7, "Threads, Exceptions, and Assertions," that reads two-digit hexadecimal sequences from a text file and displays their decimal equivalents.

    2. Write a program that reads a file to determine the number of bytes it contains and then overwrites all those bytes with zeroes (0). (For obvious reasons, don't test this program on any file you intend to keep; the data in the file will be wiped out.)

    Where applicable, exercise solutions are offered on the book's Web site at http://www.java21days.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Sams Teach Yourself Java 2 in 21 days,"...
     

    Buy this book now. This article is excerpted from chapter 15 of the book Sams Teach Yourself Java 2 in 21 days, written by Roger Cadenhead and Laura Lemay (Sams, ISBN: 0672326280). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek