當前位置:首頁 » 圖片資訊 » java如何復制一張圖片
擴展閱讀
美女健身跳河視頻 2023-08-31 22:08:21
西方貴族美女照片真人 2023-08-31 22:08:15

java如何復制一張圖片

發布時間: 2023-04-03 04:24:45

① Java如何對壓縮包里文件進行操作,把裡面的圖片文件復制到指定目錄(壓縮包裡面存在文件夾,下面的文件)

jar命令不是用來執行jar包的,是用來打包的
執行用java -jar

就樓主給的參數,寫一個例子好了含尺

1.建立MANIFEST.MF (在D:\workspace\test\class目錄下)
以下內容為文件內容
==================
Manifest-Version: 1.0
Main-Class: a(主類的路徑,此選項可選,如果希望在windows下雙擊就執行,必須寫)
Created-By: Abc Company(隨便寫,這個是創建人名字)
==================

2.打包
按照lz給的條件
在D:\workspace\test\classes\目錄下執行
jar cvfm classes.jar MANIFEST.MF *.*

以上命令將class下所有文件打包到classes.jar,生成在class目錄下橋吵

3.執行
輸入java -jar classes.jar即可執行

4.另一種方案
如果希望使用非 JAR 工具建立 JAR 文件, 建議使用 WinRAR. 首先還是需要建立一個清單文件(名字必須為MANIFEST.MF), 向此文件中寫入同使用 JAR 工具時一樣的內容, 接著需要建立一個META-INF子目錄, 然後將 MANIFEST.MF 放入此目錄, 接著就可以保持敏老侍目錄結構將所有這些內容使用 WinRAR 壓縮為 ZIP 格式的文件, 文件名取為 xxx.jar 即可.

② JAVA怎麼將一個圖片復制到文件夾中去

JDK寶典里有這樣的一段代碼,你調用File方法就可以了:

/**
* 復制單個文件, 如果目標文件存在,則不覆蓋。
* @param srcFileName 待復制的文件名
* @param destFileName 目標文件名
* @return 如果復製成功,則返回true,否則返回false
*/
public static boolean File(String srcFileName, String destFileName){
return CopyFileUtil.File(srcFileName, destFileName, false);
}

/**
* 復制單個文件
* @param srcFileName 待復制的文件名
* @param destFileName 目標文件名
* @param overlay 如果目標文件存在,是否覆蓋
* @return 如果復製成功,則返回true,否則返回false
*/
public static boolean File(String srcFileName,
String destFileName, boolean overlay) {
//判斷原文件是否存在
File srcFile = new File(srcFileName);
if (!srcFile.exists()){
System.out.println("復制文件失敗:原文件" + srcFileName + "不存在!");
return false;
} else if (!srcFile.isFile()){
System.out.println("復制文件失敗:" + srcFileName + "不是一個文件!");
return false;
}
//判斷目標文件是否存在
File destFile = new File(destFileName);
if (destFile.exists()){
//如果目標文件存在碰衡,而且復制時允許覆蓋。
if (overlay){
//刪除已存在的目標文件,無論目標文件是目錄還是單個文件
System.out.println("目標文件已存在,准備刪除它!");
if(!DeleteFileUtil.delete(destFileName)){
System.out.println("復制文件失敗:刪除目標文件" + destFileName + "失敗!");
return false;
}
} else {
System.out.println("復凱困制文件失敗:目標文件" + destFileName + "已存在!");
return false;
}
} else {
if (!destFile.getParentFile().exists()){
//如果目標文件所在的目錄不存在,則創建目錄
System.out.println("目標文件所在的目錄不存在,准備創建它!");
if(!destFile.getParentFile().mkdirs()){
System.out.println("復制文件失敗:創建目標盯吵念文件所在的目錄失敗!" );
return false;
}
}
}
//准備復制文件
int byteread = 0;//讀取的位數
InputStream in = null;
OutputStream out = null;
try {
//打開原文件
in = new FileInputStream(srcFile);
//打開連接到目標文件的輸出流
out = new FileOutputStream(destFile);
byte[] buffer = new byte[1024];
//一次讀取1024個位元組,當byteread為-1時表示文件已經讀完
while ((byteread = in.read(buffer)) != -1) {
//將讀取的位元組寫入輸出流
out.write(buffer, 0, byteread);
}
System.out.println("復制單個文件" + srcFileName + "至" + destFileName + "成功!");
return true;
} catch (Exception e) {
System.out.println("復制文件失敗:" + e.getMessage());
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();
}
}
}
}

③ 如何在一張圖片上復制另一張圖片

在圖形中復制,粘貼到另一張圖片就可以了,以下為詳細步驟說明。

工具/原料:聯想AIO520C、Windows10專業版、AutoCAD 2021

步驟:

1、首先找到復制的圖形旅好並點擊打開。

④ Java里用什麼方法把一個窗體里一張圖換到另一張圖

import javax.swing.*;
public class IS extends JFrame {
IS(){
JPanel p=new JPanel();
JLabel l=new JLabel();
Icon icon=new ImageIcon("D:\\a.jpg"); /含梁/在此直接迅銀創建對象
l.setIcon(icon);
l.setBounds(0, 0, icon.getIconWidth(),icon.getIconHeight());
p.add(l,new Integer(Integer.MIN_VALUE));
getContentPane().add(p);
pack(); //窗口適應組件大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //用來關閉畝老宴窗口的
setVisible(true);
}
public static void main(String[] a){
new IS();
}
}

⑤ java如何復制文件(包括圖片等其他格式的文件)

可以通過帶緩沖的位元組輸森基掘入輸出流來完成。下面我寫的一個小例子
import java.io.*;
public class FileTest {
public static void main(String[] args) throws FileNotFoundException {
int i;
String file="e:/電影/123/2012.rmvb";//要復制的文件路徑和名稱
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));//創建一個帶緩沖位元組輸入流讀取文件
String fileName="2012.rmvb";//文件名此核
BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("c:/my/"+fileName));//復制目的的路徑
try {
while ((i = bis.read()) != -1) {
bos.write(i);
}

} catch (IOException ex) {
ex.printStackTrace();
}finally{
try {
bis.close();
bos.close();
} catch (IOException ex) {
ex.printStackTrace();
}

}
}
}
運行鋒山正確,求採納

⑥ java中如何將上傳的圖片復制到指定文件夾中。

public static void File(File sourceFile, File targetFile) throws IOException {
BufferedInputStream inBuff=null;
BufferedOutputStream outBuff=null;
try {
// 新建文件輸入流並對它進行閉帶緩沖
inBuff=new BufferedInputStream(new FileInputStream(sourceFile));

// 新建文件姿滑輸出流並對它進行緩沖
outBuff=new BufferedOutputStream(new FileOutputStream(targetFile));

// 緩沖數組
byte[] b=new byte[1024 * 5];
int len;
while((len=inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
/跡態臘/ 刷新此緩沖的輸出流
outBuff.flush();
} finally {
// 關閉流
if(inBuff != null)
inBuff.close();
if(outBuff != null)
outBuff.close();
}
}

⑦ java 編程,復制圖片到另一文件夾下,如何提高效率

直接用文件流打開一個文件,在通過樓下說的緩沖流將文件直接寫到另外一個文件就可以了

//處理JPEG的
public static String getFixedBoundIcon(String filePath) throws Exception {

//返卜沖回地址
String result = "";
//輸出流
FileOutputStream out = null;

try {

File f = new File(filePath);
if (!f.isFile()) {
throw new Exception(f + " 不是圖片文件!");
}

//圖象文件
if (f != null && f.exists()) {

//這里的ImageIO屬於java工廠類,在工廠類class裡面,調用的System.gc(),頻繁調型散殲用會造成mp,需要考慮優化
BufferedImage image = ImageIO.read(f); // 讀入文件

if (image != null) {

BufferedImage tag =
new BufferedImage(116, 165, BufferedImage.TYPE_INT_RGB);

//繪制縮小後的圖
tag.getGraphics().drawImage(image, 0, 0, 116, 165, null);

//文件地址部分
int lastLength = filePath.lastIndexOf(".");
String subFilePath = filePath.substring(0, lastLength);
String fileType = filePath.substring(lastLength);

//背景
result = subFilePath + "_116_165" + fileType;

out = new FileOutputStream(result);

JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param =
encoder.getDefaultJPEGEncodeParam(tag);
param.setQuality(0.95f, true); //95%圖像
//像素尺寸單位.像素/英寸掘納
param.setDensityUnit(1);
//水平解析度
param.setXDensity(300);
//垂直解析度
param.setYDensity(300);
encoder.setJPEGEncodeParam(param);
encoder.encode(tag);

tag = null;

}
}

f = null;

} catch (Exception ex) {
ex.printStackTrace();
} finally {
out.close();
out = null;
}
return result;
}

還要try起來捕獲異常喲

⑧ java中的使用圖片圖標

如何復制到包拆漏里啊?我已經在電腦把圖片拷到java文件一起了,但在Eclipse的或側目旅輪爛錄樹中就是顯示不出來。桐斗

⑨ 求一個Java無損壓縮圖片的示例,把原圖片復制到指定目錄,按原圖比例改變尺寸,不影響圖片質量。

一般都是大尺寸變小尺寸,肯定有損的。

不知道你的無損是什麼意思,意思是變小尺寸了還能變大也鎮啟像以前一樣清晰?

好像有種「矢量圖片」就是可汪旅改以隨意放大縮小並且無損,缺點就是圖片困判很占空間。

⑩ 建一個新的文件夾來放圖片,在Java中這個路徑應該怎樣寫

可以寫蔽者成這樣getClass().getResource("/OAHome.png")。