2013-05-02 129 views
0

我有一個關於android內部文件的問題..我試圖寫入一些數據到一個文件,然後讀回來,但是,它似乎我不能寫入數據到文件,除非我將其轉換爲整數第一..反正是有,我可以節省兩倍或浮動值..我說我想用下面的代碼:讀/寫內部存儲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(); 
} 
+0

什麼類型是FormatCluster.mData? – dacwe 2013-05-02 13:18:15

+0

@dacwe是雙重的 – Kopiko 2013-05-02 13:21:22

回答

0

信封您的InputStream和OutputStream與DataInputStream和一個DataOutputStream類。這些類有你需要的方法

+0

你能否介紹一下如何做到這一點的教程? – Kopiko 2013-05-02 13:23:40

+0

http://journals.ecs.soton.ac.uk/java/tutorial/java/io/dataIO.html – o0rebelious0o 2013-05-02 13:24:59