java数据导入导出的问题?



java数据导入导出的问题?

如何把JTable或数据库的数据导出成.txt或.mdb(access)文件格式?
如何把.txt或.mdb(access)文件格式的数据导入到JTable或数据库中?
public void actionPerformed(ActionEvent e){
fc = new JFileChooser();
fc.setCurrentDirectory(new File(“C:\\”));
fc.setSelectedFile(new File(“*.csv”));
int retMethod = fc.showSaveDialog(fc);
int nRows = jt.getRowCount();
int nCols = jt.getColumnCount();
File f = fc.getSelectedFile();

for (int i = 0; i < nRows; i++){ //Loop through rows

for (int j = 0; j < nCols; j++){ //Loop throught columns

s+=(String)jt.getValueAt(i,j)+”,”; //Put the values in a comma seperated format
}
}
if (retMethod == JFileChooser.APPROVE_OPTION){

try{
FileWriter fw = new FileWriter(f);
fw.write(s);
fw.flush();
fw.close();

}
catch(IOException ioe){}
}
}
});