3个回答
展开全部
使用打印方法 PrintWriter类,这个类使用文本格式打印内容,比较方便
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
FileOutputStream fout;
// FileWriter fout;
int ch = 19999901;
try {
fout = new FileOutputStream("AAA.txt");
PrintWriter pwr = new PrintWriter(fout);
pwr.print(ch);
pwr.close();
System.out.println("success!");
} catch (FileNotFoundException e) {
System.out.println("error1");
} catch (IOException e) {
System.out.println("error2");
}
}
}
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
FileOutputStream fout;
// FileWriter fout;
int ch = 19999901;
try {
fout = new FileOutputStream("AAA.txt");
PrintWriter pwr = new PrintWriter(fout);
pwr.print(ch);
pwr.close();
System.out.println("success!");
} catch (FileNotFoundException e) {
System.out.println("error1");
} catch (IOException e) {
System.out.println("error2");
}
}
}
展开全部
java.lang.Object
extended by java.io.OutputStream
extended by java.io.FilterOutputStream
extended by java.io.DataOutputStream
oid writeInt(int v)
Writes an int to the underlying output stream as four bytes, high byte first.
extended by java.io.OutputStream
extended by java.io.FilterOutputStream
extended by java.io.DataOutputStream
oid writeInt(int v)
Writes an int to the underlying output stream as four bytes, high byte first.
更多追问追答
追问
import java.io.*;
class a{
public static void main(String argv[]){
FileOutputStream fout;
int ch=19999900;
try{
fout=new FileOutputStream("AAA.txt");
fout.write(ch);
fout.close();
System.out.println("success!");
}catch(FileNotFoundException e){System.out.println("error1");}
catch(IOException e){System.out.println("error2");}
}
}
求教这个为什么不行
追答
要转成 DataOutputStream 并要用 writeInt(ch);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-12-21
展开全部
楼上的可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询