流和文件

Minsc79 2004-04-16 10:07:53
从键盘输入流到文件怎么做
从文件读取信息到屏幕怎么做啊

以此方法学习流,感谢
...全文
21 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Minsc79 2004-04-17
  • 打赏
  • 举报
回复
我如何读出文件的信息呢
import java.io.*;

public class test{
public static void main(String[] args)throws IOException{

File f=new File("test.txt");
FileInputStream fis=new FileInputStream(f);

}
}
Minsc79 2004-04-17
  • 打赏
  • 举报
回复
up
lostyq 2004-04-16
  • 打赏
  • 举报
回复
up
Minsc79 2004-04-16
  • 打赏
  • 举报
回复
这么复杂啊
有没有简单点的啊,直接的
你这个我没看太懂
fruitking 2004-04-16
  • 打赏
  • 举报
回复
我有个例子


import java.io.*;
import java.applet.Applet;

public class myFile
{
public myFile()
{
init();
RecordAppend("xuguo");
}

public void init()
{
try
{
String Record="zhoukun";
String myFilePath="D:/jspServer";
String myFileName="myWriteFile.txt";
File dir=new File(myFilePath,"newFile");
dir.mkdir();
File f=new File(dir,myFileName);
FileOutputStream o=new FileOutputStream(f);
BufferedOutputStream myin=new BufferedOutputStream(o);
byte c[]=Record.getBytes();
myin.write(c);
myin.flush();
myin.close();
}
catch(IOException e)
{
System.out.println(e);
}
}

public void RecordAppend(String strAppend)
{
try
{
int filelength;
int writelength;
String myFilePath="D:/jspServer/newFile";
String myFileName="myWriteFile.txt";
File f=new File(myFilePath,myFileName);
FileOutputStream o=new FileOutputStream(f);
BufferedOutputStream myin=new BufferedOutputStream(o);
byte c[]=strAppend.getBytes();
filelength=(int)f.length();
writelength=strAppend.length();

myin.write(c,filelength,writelength);
myin.flush();
myin.close();
}
catch(IOException e)
{
System.out.println(e);
}
}

public static void main(String args[])
{
new myFile();
}
}

62,614

社区成员

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

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