您的位置:首页 > 编程语言 > Java开发

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

2018-03-30 22:10 302 查看
该项目主要用于淘宝类电商产品资源生成存储和整合

主要环境: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 =
4000
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++;
//
}
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐