JAVA之淘宝类电商的产品资源生成存储和整合

3 篇文章 0 订阅

该项目主要用于淘宝类电商产品资源生成存储和整合

主要环境:Java Mysql

主要工具 :Eclipse Navicat

上一篇:https://blog.csdn.net/linzhenyu1996/article/details/79749671

复制图片(重命名)到新路径:

    protected void copyImage() {
    	String newPath,oldPath,newp;
    	File files;
    	int ii=0;
    	oldPath=img_name_path;
    	newPath=path_to+"\\"+img_nname+".jpg";
    	copyFile(oldPath, newPath);
    	for(ii=2;ii<7;ii++) {
    		//newp=" ("+ii+")";
        	if(img_name_path.indexOf("(1)")==-1) {
        		break;
        	}
    		newp=String.valueOf(ii);
    		newp=" ("+newp+")";
        	oldPath=img_name_path.replace(" (1)",newp);
        	files=new File(oldPath);
    		if(!files.exists()) break;
        	newPath=path_to+"\\"+img_nname+"_"+(ii-1)+".jpg";
        	copyFile(oldPath, newPath);
    	}
    	i=i+(ii-2);
		System.out.println("复制图片成功!");
	}

随机字符串:

    public static String getRandomString(int length) {
	    //随机字符串的随机字符库
	    String KeyString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	    StringBuffer sb = new StringBuffer();
	    int len = KeyString.length();
	    for (int i = 0; i < length; i++) {
	       sb.append(KeyString.charAt((int) Math.round(Math.random() * (len - 1))));
	    }
	    return sb.toString();
	}

复制文件:

    public void copyFile(String oldPath, String newPath) { 
    	try { 
	    	int bytesum = 0; 
	    	int byteread = 0; 
	    	File oldfile = new File(oldPath); 
	    	if (oldfile.exists()) { //文件存在时 
		    	InputStream inStream = new FileInputStream(oldPath); //读入原文件 
		    	FileOutputStream fs = new FileOutputStream(newPath); 
		    	byte[] buffer = new byte[1444]; 
		    	int length; 
		    	while ( (byteread = inStream.read(buffer)) != -1) { 
			    	bytesum += byteread; //字节数 文件大小
			    	fs.write(buffer, 0, byteread); 
		    	} 
		    	inStream.close(); 
	    	} 
    	} 
    	catch (Exception e) { 
	    	System.out.println("复制单个文件操作出错!"); 
	    	e.printStackTrace(); 
    	} 

    } 
	public void getFileList(String strPath) {
        File dir = new File(strPath);
        files = dir.listFiles(); // 该文件目录下文件全部放入数组
    }

添加颜色属性:

    public void actionPerformed(ActionEvent e) {  
        String text = e.getActionCommand();  
        switch (text) {
		case "多种颜色":
			img_color=img_color+" colorful";
			break;
		case "紫":
			img_color=img_color+" purple";
			break;
		case "粉":
			img_color=img_color+"  rose";
			break;
		default:
			img_color=img_color+" ";
			break;
		}
        System.out.println("更新图片颜色:"+img_color);
    }
}

开始按钮监听:

		btn_skip.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO 自动生成的方法存根
				if(textField_file_from.getText().isEmpty() || textField_file_to.getText().isEmpty() || textArea_no.getText().isEmpty() || textArea_price.getText().isEmpty() ) {
					JOptionPane.showMessageDialog(null, "检查参数", "参数不足", JOptionPane.ERROR_MESSAGE); 
				}else {
					if(!begin) {
						getFileList(path_from);
						begin=true;
					}
					if(files==null) {
						JOptionPane.showMessageDialog(null, "无图片", "素材不足", JOptionPane.ERROR_MESSAGE); 
						return;
					}

//
					ImageIcon image;
					String strFileName;
					if(i>=files.length) {
						sql_conn.close();
						JOptionPane.showMessageDialog(null, "没有图片了", "素材不足", JOptionPane.ERROR_MESSAGE); 
						return;
					}
					String fileName = files[i].getName();
	                if (files[i].isDirectory()) { // 判断是文件还是文件夹
	                    getFileList(files[i].getAbsolutePath()); // 获取文件绝对路径
	                } else if (fileName.endsWith("jpg") || fileName.endsWith("png")) { // 判断文件名是否以.jpg .png结尾
	                    strFileName = files[i].getAbsolutePath();//图片路径 d:/image/img.jpg
	                    img_name_path=strFileName;
						System.out.println("源图片路径:	"+img_name_path);
	                    image = new ImageIcon(strFileName);
	            		image.setImage(image.getImage().getScaledInstance(300,300,Image.SCALE_DEFAULT));
	                    lbl_img.setIcon(image);
	                }
	                i++;
	                //
				}
			}
		});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值