模拟QQ相册上传图片

package Demo;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Tu {
    public static void main(String[] args) throws IOException {
                File f = new File("E:\\图片\\");
                String[] f1 = f.list();
                for (int i = 0; i < f1.length; i++) {
                    FileInputStream f2= new FileInputStream("E:\\图片\\"+f1[i]);
                    FileOutputStream f3 = new FileOutputStream("D:\\休闲娱乐\\壁纸\\"+f1[i]);
                    int date = 0;
                    if ((date=f2.read()) != -1){
                        f3.write(date);
                    }
                    f3.close();
                    f2.close();
                }
            }
        }






将“柜台商品管理”数据保存到本地文件中,原本的Goods[]数组作为柜台删除此行,现改为本地文件保存。

package Demo;


import java.io.*;
import java.util.Scanner;
public class demo2 {
        int num;
        private Goods[] goodses = new Goods[10];//
        //展示柜台所有的商品(不能输出null)
        private void show() throws IOException {
            System.out.println("====");
            //创建字符流过滤输入流读入
            FileReader in = new FileReader("D:\\goods.txt");
            BufferedReader br = new BufferedReader(in);//封装为过滤流
            //开始读取
            int i = 0;
            String line = null;
            //readLine()一次读取一行的字符粗
            while ((line = br.readLine())!=null) {
                String data[]=line.split(",");
                //注意类型注意类型不然运行都是null和0
                this.goodses[i] = new Goods(Integer.parseInt(data[0]),data[1], (int) Double.parseDouble(data[2]),data[3]);
                i++;
                this.num++;
            }
            //创建字符流过滤输出流读取
            FileWriter out = new FileWriter("D:\\goods.txt");
            BufferedWriter bw = new BufferedWriter(out);
            for (int j = 0; j < this.goodses.length; j++) {
                if (this.goodses[j]!=null){
                    bw.write(this.goodses[j].getId()+","+this.goodses[j].getGoodsName()+","+this.goodses[j].getPrice()+","+this.goodses[j].getDesc());
                    bw.newLine();//newLine() 写行分隔符。
                    System.out.println(goodses[j]);
                }
            }
            br.close();
            in.close();
            bw.close();
            out.close();
            System.out.println("货架目前商品数量"+num);
            return;
        }
        public void main() throws IOException {
            while(true){
                System.out.println("-------  1.展示商品    2.上架商品    ------");
                System.out.println("-------  3.下架商品    4.调整价格    ------");
                System.out.println("-------          0.退出             ------");
                //选择功能,控制台输入
                System.out.println("-->请输入功能编号:");
                int key = new Scanner(System.in).nextInt();
                //必须是0-4
                if(key<0||key>4){
                    System.out.println("-->警告:输入非法数字!!请重新输入");

                }
//根据需求跳转到相应的方法里面
                switch (key){
                    case 1:show();break;
                    case 0:System.exit(0);
                }
            }
        }
        public static void main(String[] args) throws IOException {
            demo2 d = new demo2();
            d.show();
        }

    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值