StringBuffer result = new StringBuffer();
try
{
InputStreamReader = new InputStreamReader(new FileInputStream(resource),encode);
int ch;
while ((ch = isr.read()) > -1)
{
result.append((char)ch);
}
isr.close();
} catch(IOException e) {
Log.getInstance(ReadFile.class).error("Can not open file!",e);
return false;
}
System.out.print(result.toString());
解决方案 »
- Mina比Scoket的通讯性能差距?
- 持久化优点真的好吗?
- 页面跳转
- 配置环境变量的困惑
- SOS:Struts数据库国际化问题
- 请问在TOMCAT重编译完的Class文件,要用做JAVABean使用,默认的目录是哪个目录?
- 用JBOSS+TOMCAT 作WEB容器(有EJB的)
- 关于用jdbc oci驱动jdbc thin驱动连数据库的问题
- 求前辈帮忙看看java.lang.UnsatisfiedLinkError: cn/org/bjca/sign/PDFSign.getHashValue
- Dubbo 使用http协议时,如何调用接口
- java读出excel文件内容,当是数据是数字时,数字后面会自动加上0,如(1.0)
- 请教jtable里的字段标题怎样对齐
1,resource ,encode指什么???
2,(ch = isr.read()) > -1又指什么???
import java.io.FileReader;public class Test2 { final static int START_POSITION = 5; // phone start position public static void main(String[] args) throws Exception {
StringBuffer result = new StringBuffer();
BufferedReader bw = new BufferedReader(new FileReader("test.txt"));
String line;
while ((line = bw.readLine()) != null) {
String phoneNo = line.substring(START_POSITION, START_POSITION + 11);
System.out.println(phoneNo); // or output to another file
}
bw.close();
System.out.print(result.toString());
}
}
import java.io.FileReader;public class Test {// final static int START_POSITION = 5; // phone start position public static void main(String[] args) throws Exception {
StringBuffer result = new StringBuffer();
BufferedReader bw = new BufferedReader(new FileReader("test.txt"));
String line;
int index;
while ((line = bw.readLine()) != null) {
index = line.indexOf(" "); //与文件中的空格数要一样
String phoneNo = line.substring(index, index + 11);
System.out.println(phoneNo); // or output to another file
}
bw.close();
System.out.print(result.toString());
}
}这样,不论前边的字段怎么变化都能取出!!!