当前位置: 代码迷 >> J2SE >> java 中读取特定数值的有关问题
  详细解决方案

java 中读取特定数值的有关问题

热度:21   发布时间:2016-04-24 00:47:19.0
java 中读取特定数值的问题
1.番茄 4元/个
2.鸡蛋 0.5元/个
3.螃蟹 5元/只
4.康师傅方便面 4元/盒
以上为TXT文件里的数据,现在我要使用 4 0.5 5 4 这四个数据,要怎么写
下面是我写的一部分代码
 try 
  {
  BufferedReader br = new BufferedReader(new FileReader("d:\\menu.txt"));
  String s;
  while ((s = br.readLine()) != null)
  {
  public int [] array = new int [5];

/* 保存五个数据 */  
  }
  br.close();
  } catch (FileNotFoundException e1) 
  {
  e1.printStackTrace();
  } catch (IOException e2) 
  {
  e2.printStackTrace();
  }

请问要怎么加,或者怎么修改?

------解决方案--------------------
Java code
import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.*;public class test {     public static void main(String[] args) {         try            {          BufferedReader br = new BufferedReader(new FileReader("d:\\menu.txt"));          String s;          String str2 = "";          String strNum = "";          while ((s = br.readLine()) != null)          {            String s2[] = s.split(" ");            if(s2[1] != null){                str2 = s2[1];            }            String s3[] = str2.split("元");            if(s3[1] != null){                strNum = strNum + s3[0];            }        /* 保存五个数据 */             }          System.out.println("result:"+strNum);          br.close();          } catch (FileNotFoundException e1)            {          e1.printStackTrace();          } catch (IOException e2)            {          e2.printStackTrace();          }    } }
  相关解决方案