上码import java.io.*;
public class In { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
}catch(IOException e) {
System.out.println("No File!!!!!!!!");
}
}
}我用eclipse运行了下 确实生成了个Test.txt 但里边啥都没 不死心 我又用javac编译了下 运行后还是只生成Test.txt文件 为什么呢 ??? 我明明输入了somebody \n 啊????
刚学IO 。可能问题蠢了点 呵呵
public class In { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
}catch(IOException e) {
System.out.println("No File!!!!!!!!");
}
}
}我用eclipse运行了下 确实生成了个Test.txt 但里边啥都没 不死心 我又用javac编译了下 运行后还是只生成Test.txt文件 为什么呢 ??? 我明明输入了somebody \n 啊????
刚学IO 。可能问题蠢了点 呵呵
解决方案 »
- JTree修改当前节点时,怎样获取修改后的节点名称?
- 添加了JBabel报错
- java的Integer中 parseInt(String s, int radix) 方法如何使用!!!!
- Think In Java 中的一个例子
- 一个有关public protected 的问题
- 价值几万元的学习资料拿出来共享!
- 关于BufferedInputStream,如果多个用户同时请求,所谓的缓冲区不断变大不是很容易造成内存溢出
- rmi问题,高手请进!!!
- 一个多月没哟来啦!
- JB4比JB3多了些什么?
- system.in
- 急!高分求解!java rmi 问题 !no such object in table
{
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
out.flush(); }
catch (IOException e)
{
System.out.println("No File!!!!!!!!");
}
如果你数据量小,没有占满缓冲区,没有显示地执行flush()或者close()方法,那么数据不会写到文件还有,IO部分操作的时候要有个好习惯,打开流之后一定记得关闭流,用try-catch-finally
/**
* Created by IntelliJ IDEA.
* User: admin
* Date: 2011-10-10
* Time: 11:40:58
* To change this template use File | Settings | File Templates.
*/
import java.io.*;
public class In { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
DataOutputStream out=null;
try{
out= new DataOutputStream(new BufferedOutputStream(new FileOutputStream("Test.txt")));
out.writeBytes("somebody \n");
out.flush(); }catch(IOException e) {
e.printStackTrace();
// System.out.println("No File!!!!!!!!");
}finally{
try{
out.close();
}catch(IOException e){
e.printStackTrace();
} }
}
}
首先要清空缓冲区里的数据 再关闭流
import java.io.*;
public class MyQqServer
{
public static void main(String args[])
{
File f=new File("d:/t.txt");
FileOutputStream fos=null;
byte[] b=new byte[1024];
int n=0;
try {
fos=new FileOutputStream(f);
String s="aa ";
fos.write(s.getBytes());
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
有close方法,从 java.io.FilterOutputStream 中继承过来的
在方法摘要列表下面有个小框框里有这么一段 从类 java.io.FilterOutputStream 继承的方法
close, write
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口 java.io.DataOutput 继承的方法
write