⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e10_1.java

📁 java 初学者学习实例
💻 JAVA
字号:
import java.io.*;
public class E10_1
{//将用户键盘输入的字符保存成磁盘文件,并回显在屏幕上
public static void main(String args[])
{
   char ch;
   int chi;
   File MyPath = new File("C:\\temp");
	//也可用绝对目录″c:\\temp″
   if(!MyPath.exists( ))//若此目录不存在,则创建之
     MyPath.mkdir( );
	 File MyFile1 = new File(MyPath,"crt.txt");
	 //创建指定目录下指定文件的文件类对象
	try{
	FileOutputStream fout = new 	FileOutputStream(MyFile1);
	System.out.println("Input a String 	finished with # please:");
	while((ch=(char)System.in.read( ))!='#')
	fout.write(ch);
	fout.close( );                          //关闭文件
	System.out.println("");    //换行
	FileInputStream fin = new 	FileInputStream(MyFile1); 
	while((chi=fin.read( )) != -1)
    System.out.print((char)chi);
	fin.close( );
	}     //try
	catch(FileNotFoundException e){
	System.err.println(e); 
	}    
	catch(IOException e){
	System.err.println(e); 
	}    
 }  //main( )
}  //class MyFileIo 

⌨️ 快捷键说明

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