标签:static system main title tor 数据 null 现在 操作
【例子1】
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class DataOutputStreamDemo{
public static void main(String[] args) throws IOException{
File file = new File("d:" + File.separator + "hello.txt");
char[] ch = { "A", "B", "C" };
DataOutputStream out = null;
out = new DataOutputStream(new FileOutputStream(file));
for(char temp : ch){
out.writeChar(temp);
}
out.close();
}
}
【运行结果】:
A B C
现在我们在上面例子的基础上,使用DataInputStream读出内容。
【例子2】
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class DataOutputStreamDemo{
public static void main(String[] args) throws IOException{
File file = new File("d:" + File.separator + "hello.txt");
DataInputStream input = new DataInputStream(new FileInputStream(file));
char[] ch = new char[10];
int count = 0;
char temp;
while((temp = input.readChar()) != "C"){
ch[count++] = temp;
}
System.out.println(ch);
}
}
【运行结果】:
AB
数据操作流DataOutputStream、DataInputStream类
标签:static system main title tor 数据 null 现在 操作
原文地址:https://www.cnblogs.com/yuyu666/p/9733910.html