怎样实现创建一个文件从键盘接收字符???

wwhui 2006-12-08 10:58:46
怎样实现创建一个文件从键盘接收字符???

谢谢,请支持下新手。
...全文
197 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
stefli 2006-12-09
  • 打赏
  • 举报
回复
import java.io.*;

public class WriteFile {

public static void main(String[] args) {
try
{
File file = new File("c:\\java\\test.txt");
FileOutputStream out = new FileOutputStream(file);
byte[] b = new byte[1024];

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while ((line=br.readLine())!=null) {
b = line.getBytes();
out.write(b);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
samzheng99 2006-12-09
  • 打赏
  • 举报
回复
import java.io.*;
import java.lang.*;

public class KeyInToFile{
public static void readLineFile(String toFile){
BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
RandomAccessFile raf=null;
try{
raf=new RandomAccessFile(toFile,"rw");
raf.seek(raf.length());//移动文件读写指针
String line=buff.readLine();
while (!line.equalsIgnoreCase("quit")){
raf.write(line.getBytes("GBK"));
raf.write("\r\n".getBytes("GBK"));
line=buff.readLine();
}

}catch(IOException e){
e.printStackTrace();
}

}//--readLineFile

public static void main(String[] args){

readLineFile(args[0].toString());

}//--main

}//
dr_lou 2006-12-09
  • 打赏
  • 举报
回复
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
redhat456 2006-12-09
  • 打赏
  • 举报
回复
重定义输出流System.out到文件
Pro_Vida 2006-12-08
  • 打赏
  • 举报
回复
LZ没本参考书吗?
应该多自己翻书解决啊~自己解决不了再在论坛里问啊~
书里的I/O流一章肯定有全面的解释~自己去找找
wwhui 2006-12-08
  • 打赏
  • 举报
回复
能不能写的具体点啊,大哥。
谢谢拉。
stefli 2006-12-08
  • 打赏
  • 举报
回复
创建文件去看file的操作类
FileWriter

键盘输入System.in就是了。

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧