如何用Java实现把txt文件中数据导入到mysql数据库已有的表,在线等

本人菜鸟,最好给个示例

public static void main(String[] args)throws Exception
{
String path="d:\\aa.txt";
File file=new File(path);
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis,"utf-8");
BufferedReader br=new BufferedReader(isr);
StringBuffer line=new StringBuffer();
String str=null;
File file1=new File("d:\\cc.txt");
FileOutputStream fos=new FileOutputStream(file1);
OutputStreamWriter osw=new OutputStreamWriter(fos,"utf-8");
BufferedWriter bw=new BufferedWriter(osw);
while((str=br.readLine())!=null){
line.append(str);
line.append("\n");
}
System.out.println(line);
bw.flush();
bw.close();
}

至于导入数据库,不难吧,创建个连接就可以把从流读出的数据写进去了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-06-20
找下出入数据库的代码就行了