实验8-IO流技术实验报告.docx

上传人:龙*** 文档编号:1042224 上传时间:2018-11-23 格式:DOCX 页数:11 大小:106.62KB
下载 相关 举报
实验8-IO流技术实验报告.docx_第1页
第1页 / 共11页
实验8-IO流技术实验报告.docx_第2页
第2页 / 共11页
实验8-IO流技术实验报告.docx_第3页
第3页 / 共11页
实验8-IO流技术实验报告.docx_第4页
第4页 / 共11页
实验8-IO流技术实验报告.docx_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、福建工程学院import java.awt.image.ImagingOpException;import java.io.File;import java.util.Scanner;public class Guanli 福建工程学院if(file.exists()if(file.isDirectory()String list = file.list();for(String f : list)System.out.println(f);else System.out.println(“不存在该目录! “);elseSystem.out.println(“格式错误或不存在! “);publ

2、ic static void main(String args) throws ImagingOpException/ TODO 自动生成的方法存根Scanner in= new Scanner(System.in);System.out.println(“请输 入路径:“ );String path = in.nextLine();show(path);in.close();福建工程学院import java.awt.image.ImagingOpException;import java.io.File;福建工程学院import java.io.FileOutputStream;impor

3、t java.io.IOException;import java.util.Scanner;public class Guanli public static long copyFile(String src,String dest) throws IOExceptionlong len =0;int n;if(src.equalsIgnoreCase(dest)/源文件与目标文件相同返回-1return -1;File in = new File(src);File out = new File(dest);if(in.exists()=false)/如果源文件不存在返回-2return

4、-2;if(in.isFile()=false | out.isFile()=false)/如果源文件或目标文件不是文件返回-3return -3;FileInputStream infile = new FileInputStream(in);FileOutputStream outfile = new FileOutputStream(out);while(n=infile.read()!=-1)outfile.write(n);len+;infile.close();outfile.close();return len;福建工程学院int n;File in= new File(src)

5、;File f= new File(dest);if(f.isDirectory()= false)/如果目标不是目录返回-1return -1;if(in.exists()=false)/如果源文件不存在返回-2return -2;if(in.isFile()= false)/如果源文件不是文件返回-3return -3;File out=new File(dest+in.getName();FileInputStream infile= new FileInputStream(in);FileOutputStream outfile= new FileOutputStream(out);w

6、hile(n=infile.read()!=-1)outfile.write(n);len+;infile.close();in.delete();outfile.close();福建工程学院public static void main(String args) throws IOException/ TODO 自动生成的方法存根Scanner in= new Scanner(System.in);String src,des;System.out.println(“-复制操作-“);System.out.println(“输入源文件:“ );src=in.nextLine();System

7、.out.println(“输入目标文件:“ );des=in.nextLine();System.out.println(copyFile(src, des);System.out.println(“n“);System.out.println(“-剪切操作-“);System.out.println(“输入源文件:“ );src=in.nextLine();System.out.println(“输入目标文件:“ );des=in.nextLine();System.out.println(cutFile(src, des);in.close();福建工程学院import java.io.

8、File;import java.io.FileWriter;import java.io.IOException;import java.util.Calendar;import java.util.Scanner;福建工程学院public Guanli(String path)this.path=path;public void setPath(String path)this.path=path;public String getDay() /获取系统当前时间Calendar calendar=Calendar.getInstance();String path=calendar.get

9、(Calendar.YEAR)+“-“+(calendar.get(Calendar.MONTH)+1)+“-“+calendar.get(Calendar.DAY_OF_MONTH)+“-“+calendar.get(Calendar.HOUR_OF_DAY)+“-“+calendar.get(Calendar.MINUTE);return path;public File getFile()throws IOException /创建日志文件String str= this.path+getDay()+“.log“;File File= new File(str);if(File.exis

10、ts()= false)File.createNewFile();return File;福建工程学院FileWriter fw= new FileWriter(getFile();fw.write(“登录时间 : “+ data);fw.write(“ 用户名:“ + user);fw.write(“ 密码:“ + pass);fw.close();public static void main(String args) throws IOException/ TODO 自动生成的方法存根String user;String pass;Scanner in = new Scanner(System.in);Guanli Gl= new Guanli(“E:“);while(true)System.out.println(“请输入用户名:“ );user = in.nextLine();System.out.println(“请输入密码:“ );pass = in.nextLine();if(“admin“.equals(user)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 课程笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。