IO demo: DataOutputStream and DataInputStream : Data Input Output « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » File Input Output » Data Input OutputScreenshots 
IO demo: DataOutputStream and DataInputStream


import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class DataIODemo1 {
  public static void main(String[] argsthrows IOException {
    DataOutputStream out = new DataOutputStream(new FileOutputStream(
        "Java2s.txt"));

    double[] prices = 19.999.9915.993.994.99 };
    int[] units = 128132950 };
    String[] descs = "Java""Source ""and",
        "Support."};

    for (int i = 0; i < prices.length; i++) {
      out.writeDouble(prices[i]);
      out.writeChar('\t');
      out.writeInt(units[i]);
      out.writeChar('\t');
      out.writeChars(descs[i]);
      out.writeChar('\n');
    }
    out.close();

    // read it in again
    DataInputStream in = new DataInputStream(new FileInputStream(
        "Java2s.txt"));

    double price;
    int unit;
    String desc;
    double total = 0.0;

    try {
      while (true) {
        price = in.readDouble();
        in.readChar()// throws out the tab
        unit = in.readInt();
        in.readChar()// throws out the tab
        desc = in.readLine();
        System.out.printlnunit );
        System.out.printlndesc );
        System.out.printlndesc );
        total = total + unit * price;
      }
    catch (EOFException e) {
    }
    in.close();
  }
}

           
       
Related examples in the same category
1. Data IO Test 2Data IO Test 2
2. Data IO DemoData IO Demo
3. Data IO Test Data IO Test
4. Typical I/O stream configurations
5. ProgressMonitorInputStream Demo
6. Some simple file I-O primitives reimplemented in Java
7. ScanStreamTok - show scanning a file with StringTokenizer
8. Write some data in binary
9. Using transferTo() between channels
10. Controlling serialization by adding your own writeObject() and readObject() methodsControlling serialization by adding your own writeObject() and readObject() methods
11. Read Write Lock TestRead Write Lock Test
w_w__w___._j___a___v___a_2__s_.__c__om__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.