日期:2014-05-20  浏览次数:20983 次

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

------解决方案--------------------
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();
}
}