2012-04-22 27 views
0

我正在製作一個創建floder的應用程序。在該文件夾中,我創建了一個文件並在其中寫入了Radha。但它顯示的Hello World,CreateActivity代碼在文件中寫入

Create.java

public class CreateActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    //Context ctx = getApplicationContext(); 

    try { 
     File myDir = new File(getFilesDir().getAbsolutePath()); 
     String s = ""; 

     FileWriter fw = new FileWriter(myDir + "/Test.txt"); 
     fw.write("Radha"); 
     fw.close(); 

     BufferedReader br = new BufferedReader(new FileReader(myDir + "/Test.txt")); 
     s = br.readLine(); 

     // Set TextView text here using tv.setText(s); 

    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
} 
+0

問題是...? – 2012-04-22 18:30:08

+0

我希望它顯示鐳,但它顯示你好世界,CreateActivity – 2012-04-22 18:31:33

回答

0

你寫入文件什麼無關在屏幕上什麼。檢查佈局xml(res/layout/main.xml)。 (當您撥打setContentView(R.layout.main);時,您正在使用此功能。)佈局可能引用了可在res/values/strings.xml中找到的字符串資源。更改該字符串以更改屏幕上顯示的內容。

我建議您通過Android的Hello World tutorial以瞭解這些基礎知識。

+0

ohk ..但與此代碼已創建的文件夾和Radha已寫在它..? aand我如何看到模擬器上的foler ..? – 2012-04-22 18:36:11

+1

@RadhaKumar我不知道你在努力完成什麼。您可以使用'adb'命令行工具打開一個到模擬器的shell。 (只要在命令行運行'adb shell',假設你的路徑上有平臺工具。)然後你可以查找文件和'cat'的內容。或者你也許試圖在屏幕上顯示文件內容?也許你可以澄清你的問題。 – 2012-04-22 18:41:05

+0

我想在屏幕上顯示內容...請幫助我.. – 2012-04-22 18:47:45