如何获得JTable里面的内容,然后保存到文件中? 在JTable中的内容如何获得啊,获得内容后每个字段需要用","分隔开. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // 得到列数getColumnCount()// 得到行数getRowCount() // 得到每行每列的值,返回值是Object,具体什么类型自己转。getValueAt(int row, int column) // 用,隔开不用说了吧// 用OutputStream系列或者OutputWriter系列的类保存成文件。 楼上的兄弟,拿什么点出这俩方法啊getColumnCount()/getRowCount() 我拿我的Jtable没点出来啊~~ 不会吧。假设你的table里面的值都是String。JTable table;// JTable实例化初始化// ...String fn = ""; // 文件名PrintWriter out = new PrintWriter( new BufferedWriter( new FileWriter(fn)));// 取值int rowCount = table.getRowCount();int colCount = table.getColumnCount();for (int row = 0; row<rowCount; row++){ for (int col = 0; col<colCount; col++) { Object val = table.getValueAt(row, col); out.print((String)val); if (row == rowCount - 1( { out.print(","); } else { out.println(); } }}out.close();随手写的,没测试。你自己试一下 activemq中发送者如何知道消费者是否已经收到消息 怎么样设计自己的Java命令? int型转换为String型可以么? 问个关于Applet中用Timer的问题 关于file类的问题! 小弟也想和大侠换c#程序学习 初学者遇到的一个小问题 帮忙,100就给一人 一台机器绑定多个ip,httpclient能实现用多个ip轮询访问对方网站么? 各位大佬能不能教教我关于access token方面的知识啊!!! 遇到瓶颈了!希望高手指点一二! 那个高手帮我看哈这这么调用
getColumnCount()// 得到行数
getRowCount() // 得到每行每列的值,返回值是Object,具体什么类型自己转。
getValueAt(int row, int column) // 用,隔开不用说了吧// 用OutputStream系列或者OutputWriter系列的类保存成文件。
// ...String fn = ""; // 文件名
PrintWriter out =
new PrintWriter(
new BufferedWriter(
new FileWriter(fn)));// 取值
int rowCount = table.getRowCount();
int colCount = table.getColumnCount();for (int row = 0; row<rowCount; row++){
for (int col = 0; col<colCount; col++) {
Object val = table.getValueAt(row, col);
out.print((String)val);
if (row == rowCount - 1( {
out.print(",");
} else {
out.println();
}
}
}out.close();随手写的,没测试。你自己试一下