一个txt文件放在jar中,txt文件的内容:078060*078058*078060*078058*078060*,请写出程序读取出78 、60、78、58……这样的数字.

解决方案 »

  1.   

    import java.util.jar.*;
    import java.io.*;public class Test {
    public static void main(String[] args) throws IOException {
    JarFile jarFile = new JarFile("d:/temp/test.jar");
    JarEntry dbEntry = jarFile.getJarEntry("test.txt");
    InputStream in = jarFile.getInputStream(dbEntry); int count = 2;
    int data = 0;
    int num = 0;  //保存读出来的数字
    while ((data = in.read()) != -1) {
    if (data != '*') {
    num += Math.pow(10, count--) * (data - 48);
    }
    if (count == -1) {
    System.out.println(num);
    num = 0;
    count = 2;
    }
    }
    in.close();
    jarFile.close();
    }
    }
      

  2.   

    全读出来,然后split("*");
    得到的字符串数组里面的每个元素再分成两部分078,060,然后Integer.parseInt一下.
      

  3.   

    在读取了txt中的流之后,建议首先用StringTokenizer(String target,"*");把txt中的字符串以*分割取出来到一个数组中,然后对数组中的每一项利用subString操作。
      

  4.   

    split("*");new StringTokenizer(str, "*");两种方法都可以, 建议后者...
      

  5.   

    我已经给出程序了,没看到吗?!
    把对应的d:/temp/test.jar和test.txt改成你的就可以了
      

  6.   

    num += Math.pow(10, count--) * (data - 48);
    这句是什么意思啊?
      

  7.   

    Math.pow(a, b) --> 返回a的b次方
    data --> 读出来一个数字的assic码,减去48即数字值
    一共三位数,则num = 读出第一位*100 + 读出第二位*10 + 读出第三位*1