[英]Writing in the file
I am making an app which creates a floder. 我正在制作一个可以创建花絮的应用程序。 In that folder it I am creating a file and writing Radha in it. 在该文件夹中,我正在创建一个文件并在其中写入Radha。 but it shows Hello World, CreateActivity the code is 但它显示Hello World,CreateActivity的代码是
Create.java 创建.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();
}
}
What you write into the file has nothing to do with what's on the screen. 您写入文件的内容与屏幕上的内容无关。 Check the layout xml (res/layout/main.xml). 检查布局xml(res / layout / main.xml)。 (You are using this when you call setContentView(R.layout.main);
.) The layout probably references a string resource that can be found in res/values/strings.xml. (您在调用setContentView(R.layout.main);
时使用此方法。)布局可能引用了可在res / values / strings.xml中找到的字符串资源。 Change that string to change what's displayed on the screen. 更改该字符串以更改屏幕上显示的内容。
I suggest that you go through the Hello World tutorial for Android to gain an understanding of these fundamentals. 我建议您阅读适用于Android的Hello World教程 ,以了解这些基础知识。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.