java spss_JAVA SPSS 中文乱码问题,急!

import java.io.*;

import com.pmstation.spss.*;

public class SpssTest {

// Entrance point

public static void main(String args[]) {

try {

// Open file output stream with filename args[0]

OutputStream out = new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面\\2.sav");

// Assign SPSS output to the file

SPSSWriter outSPSS = new SPSSWriter(out, "windows-1251");

// Creating SPSS variable description table

outSPSS.setCalculateNumberOfCases(false);

outSPSS.addDictionarySection(-1);

// Describing varible names and types

outSPSS.addStringVar("cont", 32, "continents of the world");

outSPSS.addNumericVar("size", 4, 0, "sq km");

outSPSS.addNumericVar("pop", 4, 0, "population");

// Create missing value

MissingValue mv = new MissingValue();

mv.setOneDescreteMissingValue(1);

outSPSS.addNumericVar("count", 4, 0, "number of countries", mv);

// Create value labels

ValueLabels valueLabels = new ValueLabels();

valueLabels.putLabel(44, "Forty four");

valueLabels.putLabel(23, "Twenty three");

outSPSS.addValueLabels(4 , valueLabels);

// Create SPSS varible value define table

outSPSS.addDataSection();

// Add values for all defined variables

outSPSS.addData("ALT升高");

outSPSS.addData(new Long(44579000L));

outSPSS.addData(new Long(3674000000L));

outSPSS.addData(new Long(44));

outSPSS.addData("Africa");

outSPSS.addData(new Long(30065000L));

outSPSS.addData(new Long(778000000L));

outSPSS.addData(new Long(53));

outSPSS.addData("North America");

outSPSS.addData(new Long(24256000L));

outSPSS.addData(new Long(483000000L));

outSPSS.addData(new Long(23));

outSPSS.addData("South America");

outSPSS.addData(new Long(17819000L));

outSPSS.addData(new Long(342000000L));

outSPSS.addData(new Long(12));

outSPSS.addData("Antarctica");

outSPSS.addData(new Long(13209000L));

outSPSS.addData(new Long(0));

outSPSS.addData(new Long(0));

outSPSS.addData("Europe");

outSPSS.addData(new Long(9938000L));

outSPSS.addData(new Long(732000000L));

outSPSS.addData(new Long(46));

outSPSS.addData("Australia/Oceania");

outSPSS.addData(new Long(7687000L));

outSPSS.addData(new Long(31000000L));

outSPSS.addData(new Long(14));

outSPSS.addData("Transelvania");

outSPSS.addData(new Long(7345560L));

outSPSS.addData(new Long(34565456L));

outSPSS.addData(new Long(44));

// Create SPSS ending section

outSPSS.addFinishSection();

// Close output stream

out.close();

}

catch (FileNotFoundException exOb) {

System.out.println("FileNotFoundException (Demo.main): " +

exOb.getMessage());

exOb.printStackTrace(System.out);

return;

}

catch (IOException exOb) {

System.out.println("IOException (Demo.main): " + exOb.getMessage());

exOb.printStackTrace(System.out);

return;

}

}

}

以上是一个测试程序,生成的.sav文件用SPSS打开,ALT升高这列中文显示乱码,怀疑是windows-1252字符问题,但是换成GBK,GB2312,UTF-8,ISO-8859-1都不行或只有个别成功。

作者: lazj1123

发布时间: 2010-05-19

  • 0
    点赞
  • 1
    收藏
  • 打赏
    打赏
  • 0
    评论
import com.pmstation.spss.DataConstants; import com.pmstation.spss.MissingValue; import com.pmstation.spss.SPSSWriter; import com.pmstation.spss.ValueLabels; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Date; public class Demo { // Entrance point public static void main(String args[]) { try { // Parse the command line if (args.length != 1) { printUsageAndExit(); } // Open file output stream with filename args[0] OutputStream out = new FileOutputStream(args[0]); // Assign SPSS output to the file SPSSWriter outSPSS = new SPSSWriter(out, "utf-8"); // Creating SPSS variable description table outSPSS.setCalculateNumberOfCases(false); outSPSS.addDictionarySection(-1); // Describing varible names and types outSPSS.addStringVar("continent", 255, "Continents of the world"); outSPSS.addNumericVar("size", 8, 2, "Sq km"); outSPSS.addNumericVar("population", 8, 2, "Population"); // Create missing value MissingValue mv = new MissingValue(); mv.setOneDescreteMissingValue(1); outSPSS.addNumericVar("countries", 8, 2, "Number of countries", mv); outSPSS.addDateVar("update", DataConstants.DATE_TYPE_17, "Date of last update", null); // Create value labels ValueLabels valueLabels = new ValueLabels(); valueLabels.putLabel("Asia", "Asia Continent"); valueLabels.putLabel("America", "America Continent"); outSPSS.addValueLabels(1, valueLabels); valueLabels = new ValueLabels(); valueLabels.putLabel(0, "No Countries"); valueLabels.putLabel(23, "Twenty Three Countries"); outSPSS.addValueLabels(4, valueLabels); outSPSS.addStringVar("description", 2200, "Description"); // Create SPSS variable value define table outSPSS.addDataSection(); // Add values for all defined variables

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页
评论

打赏作者

weixin_39624606

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值