📄 testdatastream.java
字号:
import java.io.*;
import java.util.Date;
public class TestDataStream
{
public static void main(String[] args)
{
String myStr = new String("Garbage in, garbage out");
String dirName = "C:/MyData"; // Directory name
try
{
File dir = new File(dirName); // File object for directory
if(!dir.exists()) // If directory does not exist
dir.mkdir(); // ...create it
else
if(!dir.isDirectory())
{
System.err.println(dirName + " is not a directory");
return;
}
File aFile = new File(dir, "data.txt");
aFile.createNewFile(); // Now create a new file if necessary
// Create the byte output stream
DataOutputStream myStream = new DataOutputStream(
new FileOutputStream(aFile));
myStream.writeChars(myStr); // Write the string to the file
}
catch(IOException e)
{
System.out.println("IO exception thrown: " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -