成人AV在线无码|婷婷五月激情色,|伊人加勒比二三四区|国产一区激情都市|亚洲AV无码电影|日av韩av无码|天堂在线亚洲Av|无码一区二区影院|成人无码毛片AV|超碰在线看中文字幕

使用DataOutputStream復(fù)制圖片

在io包中,提供了數(shù)據(jù)操作流:數(shù)據(jù)輸出流(DataOutputStream)和數(shù)據(jù)輸入流(DataInputStream)。通常數(shù)據(jù)輸出流會按照一定的格式將數(shù)據(jù)輸出,再通過數(shù)據(jù)輸入流按照一定的格式將數(shù)

在io包中,提供了數(shù)據(jù)操作流:數(shù)據(jù)輸出流(DataOutputStream)和數(shù)據(jù)輸入流(DataInputStream)。通常數(shù)據(jù)輸出流會按照一定的格式將數(shù)據(jù)輸出,再通過數(shù)據(jù)輸入流按照一定的格式將數(shù)據(jù)讀入。

創(chuàng)建Java項目

首先,在你使用的IDE中(比如MyEclipse或Eclipse),新建一個Java項目。右鍵點擊項目,選擇"new" -> "Java Project",輸入項目名稱并點擊"finish"。然后,右鍵項目,選擇"new" -> "package",輸入包名并點擊"finish"。接著,右鍵點擊包名,選擇"new" -> "class",輸入類名并點擊"finish"。

編寫代碼

在新建的class文件中,輸入以下代碼:

```java

package ;

import ;

import ;

import ;

import ;

import ;

import ;

public class CopyPictureDemo {

// 需求:使用DataOutputStream復(fù)制圖片

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

// 數(shù)據(jù)源:本機照片中的任意一個圖片

File srcFile new File("D:圖片Camera Roll壁紙_");

// 目的地:百度經(jīng)驗文件夾的位置

File destFile new File("D:圖片百度經(jīng)驗");

// 調(diào)用方法

method(srcFile, destFile);

}

// 創(chuàng)建一個方法進行圖片的復(fù)制操作

public static void method(File srcFile, File destFile) throws IOException {

// 封裝數(shù)據(jù)源

DataInputStream inputStream new DataInputStream(new FileInputStream(srcFile));

// 封裝目的地

DataOutputStream outputStream new DataOutputStream(new FileOutputStream(destFile));

// 創(chuàng)建一個字節(jié)數(shù)組

byte[] bys new byte[1024];

int len 0;

while ((len (bys)) ! -1) {

outputStream.write(bys, 0, len);

}

// 釋放資源

();

();

}

}

```

運行程序

右鍵點擊項目,選擇"run as",然后選擇"Java Application"執(zhí)行即可。程序會按照指定的路徑將圖片復(fù)制到指定的目錄中。

注意:以上代碼是使用DataOutputStream進行圖片復(fù)制的基本示例,你可以根據(jù)實際需求進行修改和擴展。

標簽: