当前位置: 技术问答>java相关
写入文件的数据,打开是乱码,怎么办???
来源: 互联网 发布时间:2015-08-29
本文导语: 我用randomAccessFile的writeFloat()方法向文件写入从一个Resultset中getFloat()方法读出的数据,文件打开是乱码,还有用writeChars()写入用getString()方法 从SQL SERVER 中读取的中文,打开也看不到: 瓙鐭冲寲 @瀎f@灨R@灨R@溙虭瀎...
我用randomAccessFile的writeFloat()方法向文件写入从一个Resultset中getFloat()方法读出的数据,文件打开是乱码,还有用writeChars()写入用getString()方法
从SQL SERVER 中读取的中文,打开也看不到:
瓙鐭冲寲 @瀎f@灨R@灨R@溙虭瀎fH?€I詐,就象这样。
从SQL SERVER 中读取的中文,打开也看不到:
瓙鐭冲寲 @瀎f@灨R@灨R@溙虭瀎fH?€I詐,就象这样。
|
我給你一個我寫的小程序,用它去打開你的文件看看.(你可選擇不同的編碼方式打開你的文件)
package untitled1;
import javax.swing.UIManager;
public class FormatsChange {
boolean packFrame = false;
//Construct the application
public FormatsChange() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame)
frame.pack();
else
frame.validate();
frame.setSize(600,550);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
}
new FormatsChange();
}
}
package untitled1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.*;
import com.borland.jbcl.layout.*;
import java.io.*;
public class Frame1 extends JFrame implements ActionListener{
XYLayout xYLayout1 = new XYLayout();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JLabel jLabel3 = new JLabel();
JButton jButton2 = new JButton();
String[] selectEncoding=new String[7];
JScrollPane jcs=null;
JPanel jp=new JPanel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
this.setTitle("Frame Title");
xYLayout1.setHeight(576);
xYLayout1.setWidth(559);
jLabel1.setText("選擇打開文件的編碼方式");
jButton1.setText("瀏覽");
jTextArea1.setText("jTextArea1");
jLabel2.setText("按");
jLabel3.setText("另存文件");
jButton2.setText("ok");
jp.setLayout(new BorderLayout());
jp.add("Center",jTextArea1);
jcs=new JScrollPane(jp);
this.getContentPane().add(jComboBox1, new XYConstraints(161, 22, 218, 26));
this.getContentPane().add(jButton1, new XYConstraints(398, 21, 137, 28));
this.getContentPane().add(jLabel1, new XYConstraints(20, 25, 135, 23));
this.getContentPane().add(jcs, new XYConstraints(28, 78, 509, 373));
this.getContentPane().add(jLabel2, new XYConstraints(28, 475, 24, 29));
this.getContentPane().add(jComboBox2, new XYConstraints(48, 479, 168, -1));
this.getContentPane().add(jLabel3, new XYConstraints(223, 484, 56, 21));
this.getContentPane().add(jButton2, new XYConstraints(295, 479, 173, 27));
selectEncoding[0]="GB2312";
selectEncoding[1]="Big5";
selectEncoding[2]="EUC_TW";
selectEncoding[3]="CNS11643";
selectEncoding[4]="Cp948";
selectEncoding[5]="ISO2022CN";
selectEncoding[6]="Unicode";
jButton1.addActionListener(this);
jButton2.addActionListener(this);
for(int i=0;i
package untitled1;
import javax.swing.UIManager;
public class FormatsChange {
boolean packFrame = false;
//Construct the application
public FormatsChange() {
Frame1 frame = new Frame1();
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame)
frame.pack();
else
frame.validate();
frame.setSize(600,550);
frame.setVisible(true);
}
//Main method
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
}
new FormatsChange();
}
}
package untitled1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.*;
import com.borland.jbcl.layout.*;
import java.io.*;
public class Frame1 extends JFrame implements ActionListener{
XYLayout xYLayout1 = new XYLayout();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JTextArea jTextArea1 = new JTextArea();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JLabel jLabel3 = new JLabel();
JButton jButton2 = new JButton();
String[] selectEncoding=new String[7];
JScrollPane jcs=null;
JPanel jp=new JPanel();
//Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.getContentPane().setLayout(xYLayout1);
this.setTitle("Frame Title");
xYLayout1.setHeight(576);
xYLayout1.setWidth(559);
jLabel1.setText("選擇打開文件的編碼方式");
jButton1.setText("瀏覽");
jTextArea1.setText("jTextArea1");
jLabel2.setText("按");
jLabel3.setText("另存文件");
jButton2.setText("ok");
jp.setLayout(new BorderLayout());
jp.add("Center",jTextArea1);
jcs=new JScrollPane(jp);
this.getContentPane().add(jComboBox1, new XYConstraints(161, 22, 218, 26));
this.getContentPane().add(jButton1, new XYConstraints(398, 21, 137, 28));
this.getContentPane().add(jLabel1, new XYConstraints(20, 25, 135, 23));
this.getContentPane().add(jcs, new XYConstraints(28, 78, 509, 373));
this.getContentPane().add(jLabel2, new XYConstraints(28, 475, 24, 29));
this.getContentPane().add(jComboBox2, new XYConstraints(48, 479, 168, -1));
this.getContentPane().add(jLabel3, new XYConstraints(223, 484, 56, 21));
this.getContentPane().add(jButton2, new XYConstraints(295, 479, 173, 27));
selectEncoding[0]="GB2312";
selectEncoding[1]="Big5";
selectEncoding[2]="EUC_TW";
selectEncoding[3]="CNS11643";
selectEncoding[4]="Cp948";
selectEncoding[5]="ISO2022CN";
selectEncoding[6]="Unicode";
jButton1.addActionListener(this);
jButton2.addActionListener(this);
for(int i=0;i