繁体   English   中英

写文件

[英]Writing in the file

我正在制作一个可以创建花絮的应用程序。 在该文件夹中,我正在创建一个文件并在其中写入Radha。 但它显示Hello World,CreateActivity的代码是

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

您写入文件的内容与屏幕上的内容无关。 检查布局xml(res / layout / main.xml)。 (您在调用setContentView(R.layout.main);时使用此方法。)布局可能引用了可在res / values / strings.xml中找到的字符串资源。 更改该字符串以更改屏幕上显示的内容。

我建议您阅读适用于Android的Hello World教程 ,以了解这些基础知识。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM