拆分停止在特定字符串处拆分

时间:2019-05-17 00:47:02

标签: java swing user-interface jframe indexoutofboundsexception

当我将信息从发送者发送到接收者时,我正在使用文件编写器来构建邮件系统。split方法没有进行拆分,而是到达了停止拆分的特定位置。

下面是发件人Jframe中的代码

 ArrayList<String> myArr = new ArrayList<>();

    try {
        FileInputStream fStream = new FileInputStream("Login.txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
        while (in.ready()) {
            myArr.add(in.readLine());
        }
        in.close();
    } catch (IOException e) {
        System.out.println("File input error");
    }
    String lastEmail= myArr.get(myArr.size()-1);


     FileWriter out;
    try {
        out = new FileWriter("Inbox.txt", true);
        System.out.println(jTextField1.getText());
        System.out.println(lastEmail + "," + jComboBox1.getSelectedItem().toString() + "," + jTextField1.getText() + "\n");
        out.write(lastEmail + "," + jComboBox1.getSelectedItem().toString() + "," + jTextField1.getText() +","+"c hfjch"+ "\n");
        out.close();
    } catch (IOException e) {
        System.out.println("Error appending to file " + "Inbox.txt");
    }

下面是接收器Jframe中的代码

ArrayList<String> myArr = new ArrayList<>();
    ArrayList<String> myArr2 = new ArrayList<>();
    String email = jComboBox2.getSelectedItem().toString();
    String all;
    String inbox;
    try {
        FileInputStream fStream = new FileInputStream("Inbox.txt");
        BufferedReader in = new BufferedReader(new InputStreamReader(fStream));
        while (in.ready()) {
            myArr.add(in.readLine());
        }

        in.close();
    } catch (IOException e) {
        System.out.println("File input error");
    }
    for (int i = 0; i < myArr.size(); i++) {

        String[] All = new String[4];
        All = myArr.get(i).split("/");
        String text=All[2];
            System.out.println(text);
        if(email.equals(All[0])){
            //String text=All[2];
            System.out.println(text);
            jTextArea1.setText(All[2]);
        }


    }`

”的预期结果是使用定界符分割数据,但它在第二个停止,因此收件箱中所需的数据未显示,并在线程“ AWT-EventQueue-0” java中显示了错误Exception。 lang.ArrayIndexOutOfBoundsException:2“

0 个答案:

没有答案