Java
利用输入/输出流类,从键盘上读入若干字符,然后把字符显示在屏幕上的同时,写到文件test.dat文件中。
package test1;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String str = sc.next();//读取一串连续无空格、无换行的字符
// String str = sc.nextLine();//读取一行字符,无论是否有空格或换行
System.out.println(str);
try
{
FileOutputStream out = new FileOutputStream("D:\\代码\\java\\test.dat");
out.write(str.getBytes());
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
sc.close();
}
}