欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Java復(fù)制文件程序代碼 編寫程序?qū)崿F(xiàn)文件的復(fù)制

利用JAVA語言編寫一個 名為copy的程序 實(shí)現(xiàn)文件的拷貝功能,應(yīng)該怎樣做?

import java.io.File;\x0d\x0aimport java.io.FileInputStream;\x0d\x0aimport java.io.FileNotFoundException;\x0d\x0aimport java.io.FileOutputStream;\x0d\x0aimport java.io.IOException;\x0d\x0apublic class Copy {\x0d\x0a/**\x0d\x0a* @param args\x0d\x0a*/\x0d\x0apublic static void main(String[] args) {\x0d\x0a// TODO Auto-generated method stub\x0d\x0aif(args.length!=2){\x0d\x0aSystem.out.print("沒有輸入正確數(shù)目的參數(shù),程序退出!");\x0d\x0aSystem.exit(0);\x0d\x0a}\x0d\x0aFile fileS = new File("./"+args[0]);\x0d\x0aFile fileD = new File("./"+args[1]);\x0d\x0aif(fileD.exists())System.out.println("目標(biāo)文件 "+args[1]+" 已存在!");\x0d\x0abyte[] temp = new byte[50];\x0d\x0aint totalSize = 0;\x0d\x0atry {\x0d\x0aFileInputStream fr = new FileInputStream(fileS);\x0d\x0aFileOutputStream fo = new FileOutputStream(fileD);\x0d\x0aint length = 0;\x0d\x0awhile((length = fr.read(temp, 0, temp.length)) != -1){\x0d\x0atotalSize += length;\x0d\x0afo.write(temp, 0, length);\x0d\x0a}\x0d\x0aSystem.out.println("文件 "+args[0]+" 有 "+totalSize+" 個字節(jié)");\x0d\x0aSystem.out.println("復(fù)制完成!");\x0d\x0a} catch (FileNotFoundException e) {\x0d\x0a// TODO Auto-generated catch block\x0d\x0ae.printStackTrace();\x0d\x0aSystem.out.println("源文件 "+args[0]+" 不存在!");\x0d\x0a} catch (IOException e) {\x0d\x0a// TODO Auto-generated catch block\x0d\x0ae.printStackTrace();\x0d\x0a}\x0d\x0a}\x0d\x0a}

成都創(chuàng)新互聯(lián)公司致力于網(wǎng)站制作、成都網(wǎng)站設(shè)計,成都網(wǎng)站設(shè)計,集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場競爭中脫穎而出。 選擇成都創(chuàng)新互聯(lián)公司,就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!

求大神編寫一個JAVA程序能自動復(fù)制U盤上的文件,給代碼.

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.Scanner;

public class KKKKKKKKKKK {

public static void main(String[] args) throws Exception {

Scanner scan = new Scanner(System.in);

System.out.println("請輸入U盤路徑:");

String uDisk = scan.nextLine();

File file = new File(uDisk);

if (file.exists() file.isDirectory()) {

System.out.println("請輸入目標(biāo)路徑:");

String targetFolder = scan.nextLine();

File target = new File(targetFolder);

if (!target.exists()) {

if (!target.mkdir()) {

throw new Exception("創(chuàng)建目標(biāo)目錄失敗");

}

} else {

if (!target.isDirectory()) {

throw new Exception("與目標(biāo)目錄同名的文件已經(jīng)存在");

}

}

File temp[] = file.listFiles();

if (temp != null temp.length 0) {

for (int i = 0, length = temp.length; i length; i++) {

if (!temp[i].isDirectory()) {

String fileName = temp[i].getName();

File t = new File(targetFolder+File.separator+fileName);

if (!t.createNewFile()) {

throw new Exception("創(chuàng)建輸出文件失敗");

}

FileOutputStream out = new FileOutputStream(t);

FileInputStream in = new FileInputStream(temp[i]);

byte[] buffer = new byte[256];

while (in.read(buffer) 0) {

out.write(buffer);

}

}

}

}

}

}

}

另外如果你的U盤上有目錄,并且也希望考過去的話,要加一個遞歸函數(shù) ,命令函輸入U盤所在的盤符:比如:e:\\,目標(biāo)目錄比如:c:\\abc

急求:JAVA編寫復(fù)制文件夾的代碼

一個簡單的方式就是調(diào)用cmd命令,使用windows自帶的功能來替你完成這個功能

我給你寫個例子

import java.io.*;

public class test{

public static void main(String[] args){

BufferedReader in = null;

try{

// 這里你就當(dāng)作操作對dos一樣好了 不過cmd /c 一定不要動

Process pro = Runtime.getRuntime().exec("cmd /c copy d:\\ReadMe.txt e:\\");

in = new BufferedReader(new InputStreamReader(pro.getInputStream()));

String str;

while((str = in.readLine()) != null){

System.out.println(str);

}

}catch(Exception e){

e.printStackTrace();

}finally{

if(in != null){

try{

in.close();

}catch(IOException i){

i.printStackTrace();

}

}

}

}

}

使用Java語言如何實(shí)現(xiàn)快速文件復(fù)制

使用Java語言如何實(shí)現(xiàn)快速文件復(fù)制:

代碼:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.nio.channels.FileChannel;

public class Test {

public static void main(String[] args){

long start = System.currentTimeMillis();

FileInputStream fileInputStream = null;

FileOutputStream fileOutputStream = null;

FileChannel inFileChannel = null;

FileChannel outFileChannel = null;

try {

fileInputStream = new FileInputStream(new File("C:\\from\\不是鬧著玩的.flv"));

fileOutputStream = new FileOutputStream(new File("C:\\to\\不是鬧著玩的.flv"));

inFileChannel = fileInputStream.getChannel();

outFileChannel = fileOutputStream.getChannel();

inFileChannel.transferTo(0, inFileChannel.size(), outFileChannel);//連接兩個通道,從in通道讀取數(shù)據(jù)寫入out通道。

} catch (IOException e) {

e.printStackTrace();

} finally {

try {

if(fileInputStream != null){

fileInputStream.close();

}

if(inFileChannel != null){

inFileChannel.close();

}

if(fileOutputStream != null){

fileOutputStream.close();

}

if(outFileChannel != null){

outFileChannel.close();

}

} catch (IOException e) {

e.printStackTrace();

}

}

long end = System.currentTimeMillis();

System.out.println("視頻文件從“from”文件夾復(fù)制到“to”文件需要" + (end - start) + "毫秒。");

}

}

怎樣用java程序?qū)崿F(xiàn)文件拷貝

通過輸入輸出流解決此問題,具體的可以查看JDK的API,實(shí)在不會的話,百度一下應(yīng)該都有一堆這方面的代碼。

本文標(biāo)題:Java復(fù)制文件程序代碼 編寫程序?qū)崿F(xiàn)文件的復(fù)制
轉(zhuǎn)載源于:http://chinadenli.net/article36/hjijpg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管品牌網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站微信公眾號App開發(fā)網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作