1,创建文件{File f = new File("hello.txt"); }1~,打开文件{FileOutputStream out = new FileOutputStream(f);}1~~,写文件{out.write(buf);}
2,文件关闭{out.close();}2~,打开文件{FileInputStream in = new FileInputStream(f);}2~~,读文件{byte [] buf = new byte[1024];int len = in.read(buf);}
2,文件关闭{out.close();}2~,打开文件{FileInputStream in = new FileInputStream(f);}2~~,读文件{byte [] buf = new byte[1024];int len = in.read(buf);}
解决方案 »
- 请问错在哪里呢?
- swing 页面跳转问题 求助
- 用代码添加的按钮为何显示不出来?而用GUI设计器却可以?
- 菜鸟提问:·· 谁来帮我给下面这个代码注释下·不是很懂·
- 哪位同学知道怎么样用正则表达式进行替换吗?
- dwr高手请进----关于dwr直接调用服务端Java方法并调回调函数的问题
- abstract与interface的区别?各用在什么情况下?
- 哪位高手知道,如何改变jtable中 一指定行的颜色 ?
- TCP通讯,这种情况怎么使用线程池?
- 可否解释一下wrap class(包装类)有什么用处?
- 关于LinkedList的问题,求逆置算法!
- 100分求变量类的方法调用(有输入并想要输出)问题
{// 把指定文件中的数据读出来
FileInputStream in = new FileInputStream(f);
byte [] buf = new byte[1024]; // 请问哪句指令使文件中的数据读入 byte [] buf
int len = in.read(buf); // 将当前输入流中 b.length 个字节数据读到一个字节数组中
System.out.println(new String(buf,0,len));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}