2013-05-02 1 views
0

안드로이드의 내부 파일에 관한 질문이 있습니다. 파일에 데이터를 쓰려고했지만 다시 읽으려고했지만 파일을 읽을 수없는 것처럼 보입니다. 내가 아래에 사용하기 위해 노력하고있어 코드를 추가 .. .. 나는 두 번 저장하거나 값을 플로트 수 어쨌든이 첫번째 정수로 캐스팅 :내부 기억 장치 읽기/쓰기 안드로이드

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

+0

@dacwe 두 배 – Kopiko

답변

0

봉투의 DataInputStream과 가진 당신의 InputStream 및 OutputStream에 DataOutputStream. 이 클래스에는 필요한 메소드가 있습니다

+0

이 작업을 수행하는 방법을 보여주는 자습서를 참조 할 수 있습니까? – Kopiko

+0

http://journals.ecs.soton.ac.uk/java/tutorial/java/io/dataIO.html – o0rebelious0o