急 急 急 ,请 教 斑 竹与 大 虾 们 ,输 出 到 文 件 的 可 读 性 问 题

RisingSun 2001-05-30 10:37:00
大 家 好 ,

我 试 过 用 类 似 于 (new FileWriter("myfile",true)).write ((int)xxx)这 样 的 方 法 试 图 将 输 出 结 果 存 放 在 文 件 中 . 但 打 开 myfile一 看 ,尽 是 一 个 个 黑 方 块 .请 教 如 何 能 使 存 放 的 结 果 可 读 ?
...全文
65 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmy2000 2001-05-31
  • 打赏
  • 举报
回复
Shania(魔鬼身材)说的有道理,肯定是你的fw.write(new Integer(i).toString(),0,500);
出问题了,可以在后面的catch中加入打印出错代码。
lmy2000 2001-05-30
  • 打赏
  • 举报
回复
试试:
(new FileWriter("myfile",true)).write (String xxx,0,xxx.length());
RisingSun 2001-05-30
  • 打赏
  • 举报
回复
那 么 将 (new FileWriter("myfile",true)).write ((int)xxx)改 成 (new FileWriter("myfile",true)).write ((char)xxx)就 行 了 ?
masterz 2001-05-30
  • 打赏
  • 举报
回复
只有存放字符才会可读,否则就只能用程序读
Shania 2001-05-30
  • 打赏
  • 举报
回复
fw.write(new Integer(i).toString(),0,500);
估计这一句有exeption抛出

catch (StringIndexOutOfBoundsException e){}

}
后面加上
catch(Exception e) {
System.out.println("OOPS!Exception caught!");
e.printStackTrace();
}

就知道事什么原因了

RisingSun 2001-05-30
  • 打赏
  • 举报
回复
斑 竹 ,

我 试 了 试 这 段 写 法 似 乎 也 没 用 .
fw.write(new Integer(i).toString(),0,500);
其 中 fw=new FileWriter();i=int;

另 外 ,我 还 想 问 ,在 一 段 程 序 中 我 写 了 上 面 一 句 ,则 只 打 印 了 第 一 个 结 果 .若 没 有 以 上 这 行 ,则 输 出 结 果 正 常 ,这 又 是 为 何 ?
import java.io.*;

public class Four2 {

int count=0;


void go(){
try { FileWriter fw=new FileWriter("myfile",true);

//以 下 这 段 用 于 打 印 11111至 44444间 各 位 数 只 能 为 1至 4的 数 .
for(int i=11111;i<44444;i++){
int i0=(int)Math.floor(i/10000);
int i1=(int)Math.floor((i-i0*10000)/1000);
int i2=(int)Math.floor((i—i0*10000-i1*1000)/100);
int i3=(int)Math.floor((i-i0*10000-i1*1000-i2*100)/10);
int i4=i-i0*10000-i1*1000-i2*100-i3*10;
if(i1<1||i1>4)continue;
if(i2<1||i2>4)continue;
if(i3<1||i3>4)continue;
if(i4<1||i4>4)continue;

System.out.print(i+" ");
attention: fw.write(new Integer(i).toString(),0,500);
fw.flush();
//fw.close();
count++;
if(count>256)break;

}
}catch (IOException e){}
catch (StringIndexOutOfBoundsException e){}

}

public static void main(String args[]){

Four2 four=new Four2();
four.go();


}
}

62,614

社区成员

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

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