filestream1.java

来自「这是清华大学编写的JAVA教材中所有题目的源代码!」· Java 代码 · 共 35 行

JAVA
35
字号
import java.io.*;

class FileStream1
{
	public static void main(String args[])
	{
		File f=new File("hello.txt");
		try
		{
			FileOutputStream out = new FileOutputStream(f);
			byte buf[]="hello world".getBytes();
			out.write(buf);
			out.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}

		try
		{
			FileInputStream in = new FileInputStream(f);
			byte buf[]=new byte[1024];
			int len=in.read(buf);
			System.out.println(len);
			in.close();
			System.out.println(new String(buf,0,len));
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?