




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实 验 报 告课程名称 java程序设计实用教程 实验名称 输入输出文件件处理 实验类型 设计型 实验地点 机房304 实验日期 2012-3-28 指导教师 某某人 专 业 计算机科学与技术 班 级 算机1003 学 号 * 姓 名 * 成 绩 辽宁石油化工大学计算机与通信工程学一实验目的:二实验要求:三、程序代码:代码1:package bao;import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedR
2、eader;import java.io.DataOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import javax.swing.JFrame;import javax.swing.JButton;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;i
3、mport java.io.DataInputStream;public class shiyan12 public static void main(String args) thisplay t=new thisplay();t.setSize(600,400);t.setVisible(true);t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);class thisplay extends JFrameJTextField field,field1;JTextArea display;JButton b1,b2,b3,b4;FileOut
4、putStream fo;FileInputStream fi;DataOutputStream d0;DataInputStream di;JPanel p;public thisplay()b1=new JButton("输入");b2=new JButton("输出");b3=new JButton("输入");b4=new JButton("输出");display=new JTextArea();field=new JTextField(10);field1=new JTextField(10);p=ne
5、w JPanel();Listener l=new Listener();/*p.add(field);p.add(b1);p.add(b2);p.add(field1);p.add(b3);p.add(b4);add(p,BorderLayout.NORTH);add(display);b1.addActionListener(l);b2.addActionListener(l);b3.addActionListener(l);b4.addActionListener(l);class Listener implements ActionListener public void action
6、Performed(ActionEvent e) if(e.getSource()=b1)tryfo=new FileOutputStream("E:file.dat"); d0=new DataOutputStream(fo);d0.writeChars(field.getText();d0.close();catch(IOException ex)System.out.println(ex); if(e.getSource()=b2) try fi=new FileInputStream("E:file.dat"); DataInputStream
7、di= new DataInputStream(fi); display.setText(di.readLine(); di.close(); catch(Exception ex)ex.printStackTrace(); if(e.getSource()=b3) try fo=new FileOutputStream("E:file.dat"); d0=new DataOutputStream(fo); d0.writeChars(field1.getText(); d0.close(); catch(IOException ex)System.out.println(
8、ex); if(e.getSource()=b4) try fi=new FileInputStream("E:file.dat"); /di=new DataInputStream(fi); BufferedReader d =new BufferedReader(new InputStreamReader(fi); display.setText(d.readLine(); catch(IOException ex) System.out.println(ex); 代码2:package baobao;import java.awt.BorderLayout;impor
9、t java.awt.FileDialog;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.io.PrintStream;import javax.swing.JFrame;import j
10、avax.swing.JButton;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;import java.io.DataInputStream;public class shiyan public static void main(String args) thisplay t=new thisplay();t.setSize(600,400);t.setVisible(true);t.setDefaultCloseOperation(JFrame.EXIT_ON_CL
11、OSE);class thisplay extends JFrameJTextField field,field1;JTextArea display;JButton b1,b2,b3,b4;FileOutputStream fo;FileInputStream fi;PrintStream d0;DataInputStream di;JPanel p;public thisplay()b1=new JButton("输入");b2=new JButton("输出");b3=new JButton("输入");b4=new JButt
12、on("输出");display=new JTextArea();field=new JTextField(10);field1=new JTextField(10);p=new JPanel();Listener l=new Listener();/*p.add(field);p.add(b1);p.add(b2);p.add(field1);p.add(b3);p.add(b4);add(p,BorderLayout.NORTH);add(display);b1.addActionListener(l);b2.addActionListener(l);b3.addAct
13、ionListener(l);b4.addActionListener(l);public JFrame getContainer()return this;class Listener implements ActionListenerFileDialog fd; public void actionPerformed(ActionEvent e) if(e.getSource()=b1)try fd=new FileDialog(getContainer(),"是否保存?",FileDialog.SAVE); fd.setVisible(true); FileOutpu
14、tStream out=new FileOutputStream(fd.getDirectory()+fd.getFile()+".txt"); String str = field.getText(); out.write(str.getBytes(); out.close(); catch (Exception ess) if(e.getSource()=b2) try fd=new FileDialog(getContainer(),"是否打开?",FileDialog.LOAD); fd.setVisible(true); BufferedRea
15、der in = new BufferedReader(new FileReader(fd.getDirectory() + fd.getFile(); String str = null; while (str = in.readLine() != null) display.append(str + "n"); in.close(); catch (Exception ess) if(e.getSource()=b3) try fd=new FileDialog(getContainer(),"是否保存?",FileDialog.SAVE); fd.
16、setVisible(true); FileOutputStream out=new FileOutputStream(fd.getDirectory()+fd.getFile()+".txt"); String str = field1.getText(); out.write(str.getBytes(); out.close(); catch(IOException ex)System.out.println(ex); if(e.getSource()=b4) try fd=new FileDialog(getContainer(),"是否打开?"
17、,FileDialog.LOAD); fd.setVisible(true); BufferedReader in = new BufferedReader(new FileReader(fd.getDirectory() + fd.getFile(); String str = null; while (str = in.readLine() != null) display.append(str + "n"); in.close(); catch (Exception ess) 代码3:package baoo;import java.awt.BorderLayout;
18、import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.BufferedReader;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintStream;import javax.swing.JFrame;import javax.swing.JBut
19、ton;import javax.swing.JPanel;import javax.swing.JTextArea;import javax.swing.JTextField;import java.io.DataInputStream;public class shiyan public static void main(String args) thisplay t=new thisplay();t.setSize(600,400);t.setVisible(true);t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);class this
20、play extends JFrameJTextField field,field1;JTextArea display;JButton b1,b2,b3,b4;FileOutputStream fo;FileInputStream fi;PrintStream d0;DataInputStream di;JPanel p;public thisplay()b1=new JButton("输入");b2=new JButton("输出");b3=new JButton("输入");b4=new JButton("输出&quo
21、t;);display=new JTextArea();field=new JTextField(10);field1=new JTextField(10);p=new JPanel();Listener l=new Listener();/*p.add(field);p.add(b1);p.add(b2);p.add(field1);p.add(b3);p.add(b4);add(p,BorderLayout.NORTH);add(display);b1.addActionListener(l);b2.addActionListener(l);b3.addActionListener(l);b4.addActionListener(l);class Listener implements ActionListener public void actionPerformed(ActionEvent e) if(e.getSource()=b1)tryfo=new FileOutputStream("E:file.dat"); d0=new PrintStream(fo);d0.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030年中国高合金钢衬板数据监测研究报告
- 梅花链罩项目可行性研究报告
- 圣诞新品发布盛典
- 腮腺炎防病知识
- 旅游湾区项目提案
- 设计师2025年终总结
- 基于隐性债务风险导向的PPP项目审计研究
- 基于FBG感知的套管柔性针穿刺路径规划及控制
- PeGα3、PeRgsA和PeRgsB调节扩展青霉生长发育、毒素和色素合成及致病性
- 2024年江苏徐州医科大学招聘笔试真题
- 江苏省南通市通州区通州区育才中学2023-2024学年英语八下期末检测试题含答案
- 【美妆产品的直播带货营销策略探究:以花西子彩妆为例12000字(论文)】
- 静配中心肠外营养液TPN药物配置的操作方法课件
- 2024年浙江省宁波市外事服务中心招聘2人历年(高频重点复习提升训练)共500题附带答案详解
- 废活性炭管理制度范文
- YYT 0972-2016 有源植入医疗器械 植入式心律调节设备用四极连接器系统 尺寸和试验要求
- 公司变更法人协议书模板
- DL-T5161.17-2018电气装置安装工程质量检验及评定规程第17部分:电气照明装置施工质量检验
- 2024年共青团入团积极分子结业考试题库及答案
- 实施医院安全巡查管理制度
- 2024秋季山西交控集团所属路桥集团校园招聘270人高频考题难、易错点模拟试题(共500题)附带答案详解
评论
0/150
提交评论