【问题标题】:read/write internal storage android读/写内部存储android
【发布时间】:2013-05-02 13:16:08
【问题描述】:

我有一个关于 android 中的内部文件的问题。我尝试将一些数据写入文件然后将其读回,但似乎我无法将数据写入文件,除非我先将其转换为整数.. 无论如何我可以保存双精度或浮点值。我在下面添加了我尝试使用的代码:

FormatCluster formatCluster = ((FormatCluster)objectCluster.returnFormatCluster(ofFormats,"Calibrated")); 
if (formatCluster != null) {
//Obtain data for text view
calibratedDataArray[0] = formatCluster.mData;
calibratedUnits = formatCluster.mUnits;
A.setText("data: " + formatCluster.mData);

String filename = "myfile";
//String string = "Hello world!";
FileOutputStream outputStream;

try {
  outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
  outputStream.write((int)formatCluster.mData);//here I don't want to cast the value to integer
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}

//testing.setText)

double ch;
StringBuffer fileContent = new StringBuffer("");
FileInputStream fis;
try {
fis = context.openFileInput( filename );
try {
while( (ch = fis.read()) != -1)
testing.setText(fileContent.append(ch));
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}

【问题讨论】:

  • FormatCluster.mData是什么类型?

标签: java android storage internal


【解决方案1】:

用 DataInputStream 和 DataOutputStream 封装您的 InputStream 和 OutputStream。这些类有你需要的方法

【讨论】:

  • 能否请您参考一个说明如何执行此操作的教程?
猜你喜欢
  • 1970-01-01
  • 2018-05-24
  • 2012-06-07
  • 1970-01-01
  • 2014-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多