IO demo: DataOutputStream and DataInputStream : Data Input Output : File Input Output : Java examples (example source code) Organized by topic

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. JSP
19. JSTL
20. Language Basics
21. Network Protocol
22. PDF RTF
23. Regular Expressions
24. Security
25. Servlets
26. Spring
27. Swing Components
28. Swing JFC
29. SWT JFace Eclipse
30. Threads
31. Tiny Application
32. Velocity
33. XML
Java Tutorial
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
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.