超市系统扩展

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class AddInData {
    private String al=new String();
    String path;
    Scanner sc=new Scanner(System.in);
    public void AddInData(String path){
        //输入信息
        al=sc.next();
        //存入信息
        File f=new File(path);
        FileOutputStream fis=null;
        try {
            byte[] b=al.getBytes();
            fis=new FileOutputStream(f);
            fis.write(b);
            fis.flush();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

创建AddInData类里面有一个同名方法传入文件路径可以实现输入字符串把字符串存入文件里面

import java.io.IOException;
import java.util.Arrays;

public class ReadData {
    public void ReadData(String path){
        File f=new File(path);
        FileInputStream fis=null;
        try {
            fis=new FileInputStream(f);
            byte[] bytes=new byte[10];
            fis.read(bytes);

           for (int i=0;i<bytes.length;i++){
               System.out.print((char) bytes[i]);
               if (bytes[i+1]==0){break;}
           }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                fis.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

我们创建ReadData方法用来读取文件的内容

public class GoodsSearchIn {
    int index;
    private String path;
    public void GoodsSearchIn(int index){
        switch (index){
           case  1:
              path="E:\\商品中心\\VivoY97.txt\\";
               ReadData readData=new ReadData();
               readData.ReadData(path);
               break;
    }

}
}
public class Main {
    public static void main(String[] args) {
        //以下为测试区
        GoodsSearchIn goodsSearchIn=new GoodsSearchIn();
        goodsSearchIn.GoodsSearchIn(1);

        //以上为测试区
        LoginInterface l=new LoginInterface();
        l.LoginInterface();
    }
}

添加一个GoodsSearchIn方法用户可以通过传入标记查询商品

import java.util.Scanner;

public class GoodsSearch {
    Scanner sc=new Scanner(System.in);
    GoodsSearchIn goodsSearchIn=new GoodsSearchIn();
    public void GoodsSearch(){
        System.out.println("这里是搜索框");
        System.out.println("商品大全如下");
        System.out.println("1-VivoY97");
System.out.println("用户请输入数字");
        int sr=sc.nextInt();
        goodsSearchIn.GoodsSearchIn(sr);
        
    }
}

添加GoodsSearch方法指示用户

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值