Computer Science

Java IO Package

The Java IO Package is a collection of classes and interfaces that provide input and output functionality for Java programs. It allows programs to read and write data from various sources, such as files, network connections, and user input. The package includes classes for both character and byte-based input and output.

Written by Perlego with AI-assistance

3 Key excerpts on "Java IO Package"

  • Book cover image for: JAVA Programming Simplified
    eBook - ePub

    JAVA Programming Simplified

    From Novice to Professional - Start at the Beginning and Learn the World of Java

    Most of the functionality in Java is implemented through classes stored in different Java API packages. The classes are grouped together based on their functionalities and are provided to a programmer in the form of a package. Some of the frequently used Java packages are as under:
    Package Name Classes
    java.lang It includes the language support classes suchas. Integer, String, Thread, and more.
    java.util It includes vast variety of utility classes like Date, Random, and more.
    java.awt In order to create a GUI type of an application, this package is imported. It includes classes like Button, Frame, TextField, and more.
    java.io
    To deal with input / output in Java, the io package is required. This package will be discussed in
    Chapter 9: Input Output in Java .
    java.sql
    This sql package is used for the database connectivity. It includes classes like Connection, DriverManager, ResultSet, and more. This package will be discussed in
    Chapter 11: Java Database Connectivity .
    java.event
    Event Handling is implemented through java.event. This package will be discussed in
    Chapter 10: Event Handling in Java .
    java.applet
    It includes the Applet class used to create the user defined applets. This package will be discussed in
    Chapter 9: Input Output in Java .
    Table 4.2: Inbuilt packages in Java

    java.lang package

    The java.lang is the default package in Java. If we want to use any of its class, we need not to import it as it is imported automatically to our Java program. The following table lists some of the classes available in java.lang
  • Book cover image for: Object-Orientation, Abstraction, and Data Structures Using Scala
    • Mark C. Lewis, Lisa Lacher, Lisa L. Lacher(Authors)
    • 2017(Publication Date)
    Chapter 10

    Stream I/O and XML

    10.1  The java.io Package 10.2  Streams for Files Wrapping an InputStream in a Source 10.3  Exceptions 10.3.1  try-catch-finally Revisited 10.3.2  Effect of Exceptions 10.3.3  Loan Pattern 10.4  Decorating Streams 10.4.1  Buffering Latency and Bandwidth 10.4.2  Binary Data Big Endian vs. Little Endian 10.5  Serialization 10.5.1  Binary Serialization Custom Serialization 10.5.2  XML Serialization 10.5.2.1  Nature of XML 10.5.2.2  XML in Scala Code 10.5.2.3  Serializing to XML Compressed Streams 10.6  Saving Drawings (Project Integration) 10.7  End of Chapter Material 10.7.1  Summary of Concepts 10.7.2  Exercises 10.7.3  Projects
    In chapter 1 we saw how to use scala.io.Source and java.util.Scanner to read from text files. We also saw how we could use java.io.PrintWriter to write text files. In this chapter we will explore the overall structure of the java.io package and see how streams can be used to represent a general approach to input and output. This will set us up in the following chapter to use streams for network communication. We will also explore the use of XML in Scala as another format for storing or communicating data.

    10.1    The java.io Package

    The original library for doing input and output in Java was the java.io package. While there is now a java.nio package (non-blocking io) that can provide higher performance, the original library is still used as a foundation for many other parts of the Java libraries, which makes it worth knowing and understanding.
    The majority of the classes in the java.io package are subtypes of one of four different abstract types: InputStream, OutputStream, Reader , and Writer . The InputStream and OutputStream have basic operations that work with Bytes . The Reader and Writer have almost the same set of methods, but they work with Chars . Here are the signatures of the methods in InputStream
  • Book cover image for: C# For Java Programmers
    • Harold Cabrera(Author)
    • 2002(Publication Date)
    • Syngress
      (Publisher)
    Working with I/O Streams Solutions in this chapter: 406 Chapter 11 • Working with I/O Streams Introduction One of Java’s great features is providing a layer of abstraction for performing input/output and networking operations.The Java model for IO uses streams, something familiar to most Java programmers. C# also uses streams and provides a rich set of libraries for hiding the complications of data transfer.The counterpart of the java.io package is the System.IO namespace. Classes in the System.IO namespace allow you to read and write information to a file, or to the console. Other pack-ages, such as System.Net.Socket, support streams for network connections. File System In Java, files and directories are handled using a single class called File .This ambiguous design sometimes leads to confusion since it can be difficult to deter-mine if a file or directory is being used. C# distinguishes between files and direc-tories by giving us two classes to handle disk operations: File and Directory .These two classes use only static methods to perform disk operations, but there are also two corresponding classes that perform disk operations on instances: FileInfo and DirectoryInfo . For Java programmers, the latter seems more familiar. C# uses a base class for FileInfo and DirectoryInfo called FileSystemInfo .This base class contains only methods that are common to both directories and files. Many of the methods in FileSystemInfo have counterparts in java.io.File . C# also has methods that have no counterpart in Java, since the Java strategy is to create only methods that are universal across different platforms. For example, methods for accessing the last time a file was accessed or when a file was created are unique to C#. Directories The two classes for handling directories are Directory and DirectoryInfo .
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.