截取文件内容,存入数据库里 a1 001 北京a2 002 北京a3 003 北京a4 004 北京a5 005 北京a6 006 北京a7 007 北京从文本中读取文件数据。我已经会了。可是不会如果截取这三列,存入mysql里。谢谢大家的帮助 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.用BufferedReader类 的readLine()读出一行2.用.split(" ")分割字符串.3.传成相应类型数据4.写入数据库 你以行一行的读,再把每一行使用StringTokenizer按照空格分开,只取前三个就可以了 a1 001 北京 a1 001 北京 a1 001 北京 a1 001 北京 a1 001 北京 a1 001 北京 a1 001 北京 截取之后是这样的以前没用过IO。谢谢你们了。。 代码是这样的。。public class Test_1 { /** * * Test类主函数 * * @param args * @throws IO异常 */ public String[] ss = new String[200]; public static void main(String[] args) throws IOException { String path = "d:\\test.txt"; Test_1 t = new Test_1(); if (t.isExist(path)) { if (t.isEmpty(path)) { System.out.println("success!"); System.out.println(); t.getValue(path); } else { System.out.println("false!"); } } else { System.out.println("false!"); } } /** * * 判断文件是否存在 * * @param file 文件名 * @return 文件是否存在 * true - 文件存在 * false - 文件不存在 */ boolean isExist(String file) { File f = new File(file); if (f.exists()) { System.out.println("File is Exist!"); return true; } else { System.out.println("File isn't Exist!"); return false; } } /** * * 判断文件是否为空 * * @param file 文件名 * @return 文件是否为空 * true - 文件为空 * false - 文件不为空 * @throws IO异常 */ boolean isEmpty(String file) throws IOException { FileReader fr = new FileReader(file); if (fr.read() == -1) { System.out.println("File is Empty!"); return false; } else { System.out.println("File isn't Empty!"); return true; } } /** * * 读取文件 * * @param file 文件名 * @throws IO异常 */ void getValue(String file) throws IOException { FileReader fr; fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String line = ""; line = br.readLine(); ss = line.split(" "); while (line !=null) { for(int i=0;i<ss.length;i++) { System.out.print(ss[i]+" "); } System.out.println(); line = br.readLine(); } // while (line != null) {// String lineNew = "";// lineNew = line;// System.out.println(lineNew);// line = br.readLine();// } }} 求代码 为什么获取额时间都和当前时间不一致呢 急问Java规范里方法可以使用哪些字符? 求助!!!看看下面两段代码有什么区别。 MidiSystem.getSequencer(false/true) 的作用 游戏中的打怪,怎么来实现,请高手指教 JAVA连接ORACLE8I时报错:java.sql.SQLException: Io 异常 请教写过JAVA滑行菜单的朋友 棘手的问题:java 1.4中如何获取环境变量? 关于把String转成二进制数组的问题,急 线程问题,关于synchronized 一个文件拆分合并的方法
a1 001 北京
a1 001 北京
a1 001 北京
a1 001 北京
a1 001 北京
a1 001 北京 截取之后是这样的以前没用过IO。谢谢你们了。。
{ /**
*
* Test类主函数
*
* @param args
* @throws IO异常
*/
public String[] ss = new String[200];
public static void main(String[] args) throws IOException
{
String path = "d:\\test.txt";
Test_1 t = new Test_1();
if (t.isExist(path)) {
if (t.isEmpty(path)) {
System.out.println("success!");
System.out.println();
t.getValue(path);
} else {
System.out.println("false!");
}
} else {
System.out.println("false!");
}
}
/**
*
* 判断文件是否存在
*
* @param file 文件名
* @return 文件是否存在
* true - 文件存在
* false - 文件不存在
*/
boolean isExist(String file)
{
File f = new File(file);
if (f.exists()) {
System.out.println("File is Exist!");
return true;
} else {
System.out.println("File isn't Exist!");
return false;
}
}
/**
*
* 判断文件是否为空
*
* @param file 文件名
* @return 文件是否为空
* true - 文件为空
* false - 文件不为空
* @throws IO异常
*/
boolean isEmpty(String file) throws IOException {
FileReader fr = new FileReader(file);
if (fr.read() == -1) {
System.out.println("File is Empty!");
return false;
} else {
System.out.println("File isn't Empty!");
return true;
}
}
/**
*
* 读取文件
*
* @param file 文件名
* @throws IO异常
*/
void getValue(String file) throws IOException {
FileReader fr;
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line = "";
line = br.readLine();
ss = line.split(" ");
while (line !=null)
{
for(int i=0;i<ss.length;i++)
{
System.out.print(ss[i]+" ");
}
System.out.println();
line = br.readLine();
}
// while (line != null) {
// String lineNew = "";
// lineNew = line;
// System.out.println(lineNew);
// line = br.readLine();
// }
}
}