帮我看看这是什么错误,谢谢

xsmile 2003-12-12 11:09:38
java.io.FileNotFoundException: page (拒绝访问。)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at bbs_class.Zip.main(Zip.java:34)
...全文
37 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xsmile 2003-12-12
  • 打赏
  • 举报
回复
解决了,谢谢
xsmile 2003-12-12
  • 打赏
  • 举报
回复
up一下
帮帮我
xsmile 2003-12-12
  • 打赏
  • 举报
回复
import java.util.zip.*;

import java.awt.event.*;

import java.awt.*;

import java.lang.Math;

import java.io.*;

public class TestZip extends Frame implements ActionListener {

TextArea textarea; //显示数据文件的多行文本显示域

TextField infotip; //显示数据文件未压缩大小及压缩大小单行文本显示域

String doc; //存储随机生成的数据

long doczipsize = 0;//压缩数据文件的大小

public TestZip(){

//生成菜单

MenuBar menubar = new MenuBar();

setMenuBar(menubar);

Menu file = new Menu("File",true);

menubar.add(file);

MenuItem neww= new MenuItem("New");

neww.addActionListener(this);

file.add(neww);

MenuItem open=new MenuItem("Open");

open.addActionListener(this);

file.add(open);

MenuItem save=new MenuItem("Save");

save.addActionListener(this);

file.add(save);

MenuItem exit=new MenuItem("Exit");

exit.addActionListener(this);

file.add(exit);

//随机生成的数据文件的多行文本显示域

add("Center",textarea = new TextArea());

//提示文本原始大小、压缩大小的单行文本显示域

add("South",infotip = new TextField());

}

public static void main(String args[]){

TestZip ok=new TestZip();

ok.setTitle("zip sample");

ok.setSize(600,300);

ok.show();

}

private void randomData(){

//随机生成50个double数据,并放在doc字符串变量中。

doc="";

for(int i=1;i<51;i++){

double rdm=Math.random()*10;

doc=doc+new Double(rdm).toString();

if(i%5 == 0) doc=doc+"n";

else doc=doc+" ";

}

doczipsize = 0;

showTextandInfo();

}

private void openFile(){

//打开zip文件,将文件内容读入doc字符串变量中。

FileDialog dlg=new FileDialog(this,"Open",FileDialog.LOAD);

dlg.show();

String filename=dlg.getDirectory()+dlg.getFile();

try{

//创建一个文件实例

File f=new File(filename);

if(!f.exists()) return; //文件不存在,则返回

//用文件输入流构建ZIP压缩输入流

ZipInputStream zipis=new ZipInputStream(new FileInputStream(f));

zipis.getNextEntry();

//将输入流定位在当前entry数据项位置

DataInputStream dis=new DataInputStream(zipis);

//用ZIP输入流构建DataInputStream

doc=dis.readUTF();//读取文件内容

dis.close();//关闭文件

doczipsize = f.length();//获取ZIP文件长度

showTextandInfo();//显示数据

}

catch(IOException ioe){

System.out.println(ioe);

}

}

private void saveFile(){

//打开zip文件,将doc字符串变量写入zip文件中。

FileDialog dlg=new FileDialog(this,"Save",FileDialog.SAVE);

dlg.show();

String filename=dlg.getDirectory()+dlg.getFile();

try{

//创建一个文件实例

File f=new File(filename);

if(!f.exists()) return; //文件不存在,则返回

//用文件输出流构建ZIP压缩输出流

ZipOutputStream zipos=new ZipOutputStream(new FileOutputStream(f));

zipos.setMethod(ZipOutputStream.DEFLATED); //设置压缩方法

zipos.putNextEntry(new ZipEntry("zip"));

//生成一个ZIP entry,写入文件输出流中,并将输出流定位于entry起始处。

DataOutputStream os=new DataOutputStream(zipos);

//用ZIP输出流构建DataOutputStream;

os.writeUTF(doc);//将随机生成的数据写入文件中

os.close();//关闭数据流

doczipsize = f.length();

//获取压缩文件的长度

showTextandInfo();//显示数据

}

catch(IOException ioe){

System.out.println(ioe);

}

}

private void showTextandInfo(){

//显示数据文件和压缩信息

textarea.replaceRange(doc,0,textarea.getText().length());

infotip.setText("uncompressed size: "+doc.length()+"compressed size: "+doczipsize);

}

public void actionPerformed(ActionEvent e){

String arg = e.getActionCommand();

if ("New".equals(arg)) randomData();

else if ("Open".equals(arg)) openFile();

else if ("Save".equals(arg)) saveFile();

else if ("Exit".equals(arg)){

dispose();//关闭窗口

System.exit(0);//关闭程序

}

else {

System.out.println("no this command!");

}

}

}
我从网上找的。但是好像没有打开文件吧,谢谢了,帮我看看
DainelLee 2003-12-12
  • 打赏
  • 举报
回复
没找到文件

62,634

社区成员

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

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