我有一个带有中文字符的Jtable,而我试图将数据提取到数组列表中,它显示为???????,在eclipse控制台中显示它正常,但在html文件中显示它棘手。如何将JTable数据读入具有特殊字符(如中文)的ArrayList?
package test.java;
import javax.swing.*;
public class TableExample
{
JFrame f;
JTable jt ;
public JTable m1()
{
f=new JFrame();
String data[][]={ {"100","你叫什么名字? ","1234"},
{"111","プードル","4567"},
{"222","유모차","343124"}};
String column[]={"ID","NAME","SALARY"};
jt=new JTable(data,column);
jt.setBounds(30,40,200,300);
JScrollPane sp=new JScrollPane(jt);
f.add(sp);
f.setSize(300,400);
f.setVisible(true);
return jt;
}
}
第二程序读取数据和写入数据到一个HTML文件中,我看不到我的特殊字符
package test.java;
import java.util.ArrayList;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JTable;
public class TableClass {
public static void main(String[] args)
{
ArrayList<String> numdata = new ArrayList<String>();
TableExample mainTable = new TableExample();
JTable table = mainTable.m1();
for (int count = 0; count < table.getRowCount(); count++)
{
numdata.add(table.getValueAt(count, 1).toString());
}
FileWriter writer = null;
try
{
writer = new FileWriter("D:/Testing.html");
} catch (IOException e)
{
e.printStackTrace();
}
for(String str: numdata)
{
try
{
writer.write(str);
} catch (IOException e)
{
e.printStackTrace();
}
}
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这很可能是用于呈现文本的字体的一个问题 – MadProgrammer
在执行代码时,我得到一个例外,即“ArrayList numdata”不能转换为“CharSequence”。这是你的实际代码吗? – cello
将'System.out.println'行更改为'for(Object o:numdata){System.out.println(“TableClass.main()”+ o); }'为我打印正确的字符。所以它可能是控制台中使用的字体或控制台的字符编码问题。 – cello