簡體   English   中英

讀/寫內部存儲android

[英]read/write internal storage android

我有一個關於android中內部文件的問題。我試圖將一些數據寫入文件,然后將其讀回,但是,除非我先將其轉換為整數,否則似乎無法將數據寫入文件。無論如何,我都可以保存double或float值。我在下面添加了我要使用的代碼:

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();
}

用DataInputStream和DataOutputStream包圍InputStream和OutputStream。 這些類具有您需要的方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM