JAVA文件复制小程序
来源:互联网 发布:ios 读取网页数据 编辑:程序博客网 时间:2024/05/18 09:05
JAVA文件复制小程序
复制功能
- package tsc.function;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- /**
- * 文件复制功能
- * @author qiuyue
- *
- */
- public class CopyFile {
- public static boolean copyFile(String source,String file) {
- int byteread = 0;
- InputStream in = null;
- OutputStream out = null;
- try {
- in = new FileInputStream(source);
- out = new FileOutputStream(file);
- byte[] buffer = new byte[2048];
- while((byteread = in.read(buffer)) != -1) {
- out.write(buffer, 0, byteread);
- }
- System.out.println("复制成功");
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }finally {
- if(out != null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- if(in != null) {
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }
前端
package tsc; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Timer; import javax.swing.*; import tsc.function.MyTask.myTask; public class MyFrame extends JFrame{ private static final long serialVersionUID = 371204056893587903L; public MyFrame() { this.setTitle("文件移动工具"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(300, 150); this.setLocationRelativeTo(null); this.setResizable(false); this.setLayout(new GridLayout(1, 2)); JButton start = new JButton("移动"); JButton exit = new JButton("退出");JFrame frame1 = new JFrame("运行提示");JFrame frame2 = new JFrame("运行提示"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { File file = new File(Data.SOURCE);if(file.exists()){CopyFile.copyFile(Data.SOURCE,Data.PATH);frame1.setLocationRelativeTo(null);frame1.setSize(240, 150);frame1.setVisible(true);JLabel label = new JLabel("移动成功",JLabel.CENTER);label.setFont(new java.awt.Font("Dialog",0,15));JButton quit = new JButton("确定");frame1.getContentPane().add("South",quit);frame1.getContentPane().add("Center",label);quit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent arg0){frame1.setVisible(false);}});}else{frame2.setLocationRelativeTo(null);frame2.setSize(240,150);frame2.setVisible(true);JLabel label = new JLabel("移动失败,未找到文件",JLabel.CENTER);label.setFont(new java.awt.Font("Dialog",0,15));JButton quit = new JButton("确定");frame1.getContentPane().add("South",quit);frame1.getContentPane().add("Center",label);quit.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent arg0){frame2.setVisible(false);}});} } }); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); getContentPane().add(start); getContentPane().add(exit); } }Data
package tsc; public class Data { //源文件所在绝对路径 public static final String SOURCE = "E:/ceshi/Source/source.bin"; //转移到的绝对路径 public static final String PATH = "E:/ceshi/Test/source.bin";Main
package tsc; import tsc.MyFrame; public class Main { public static void main(String[] args) { new MyFrame().setVisible(true); } }
阅读全文
0 0
- JAVA文件复制小程序
- 小程序-----JAVA代码实现文件内容的复制
- Java文件查找小程序
- NodeJS 小文件复制
- java小程序--筛选和移动文件
- 删除文件的Java小程序
- java单文件编译辅助小程序
- java小程序打包成.exe文件
- 复制小程序,去空洞
- 复制字符串小程序笔记
- redis主从复制小程序
- Dos(cmd)窗口下运行 JAVA程序(文件复制)
- 怎样用java写一个简单的文件复制程序
- 一个简单的实现复制文件并修改文件扩展名的小程序
- linux大量小文件复制
- 通过C++文件复制小程序来理解read、write函数
- 文件复制程序 file_copy.c
- Java数组复制小例子
- jsp页面onclick 事件使用post方式提交请求
- 部署java-web项目到linux服务器上
- Linux中pwd的参数差异
- angular开发中我认为好用的插件
- linux下Oracle11g RAC搭建
- JAVA文件复制小程序
- angularJs自定义指令的scope配置详解
- 预加重/去加重/直流滤波
- 数据库中间件TDDL调研笔记
- Android学习笔记之Broadcast Receiver
- Javascript函数调用,参数传递,闭包和作用域实例分析
- IDEA 2017 2.2常见的编译错误以及解决办法
- Kotlin 语言高级安卓开发入门
- Hive分区修复命令MSCK介绍与使用