Android应用程序/ Android的Studio中显示C $ C $Ç [英] Display C code inside the Android App/ Android Studio
问题描述
我目前工作的一个Android应用程序,以帮助我的同学来学习C语言的。我是pretty与应用程序的设计和布局做多,而且甚至设法把解释与例子。但我真的不知道如何显示在应用程序中的C程序。
I'm currently working on an android app to help my fellow classmates to learn C language. I'm pretty much done with the design and layout of the app, and have even managed to put explanation with example. But I really don't know how to display the C programs inside the app.
我读过有关显示HTML code和读/从原始文件夹中的文本文件显示,但我不认为这会证明是有益的在这里。另外,我是新来的Java / Android的工作室的东西,所以我要求你们都张贴有一点解释了一下详细的解答。
I've read about displaying HTML code and reading/displaying from a text file in raw folder but I don't think that'd prove helpful here. Plus I'm new to Java/Android Studio stuff so I request you all to post a bit detailed answer with little explanation.
我不一定要在C code到是颜色突出或prettified,这将是不够的,如果我能以某种方式显示出来。
I don't necessarily want the C code to be color highlighted or prettified, it would be enough if I could just somehow display it.
推荐答案
这是简单的方法来实现,这将是与存储code在一个文件中(的 http://developer.android.com/training/basics/data-storage/files.html ),并从那里读的每时间用户打开其中code可以看出的活性。
An easy way to achieve this would be with storing the code in a file ( http://developer.android.com/training/basics/data-storage/files.html ) and reading from there every time the user opens the activity where the code can be seen.
记住:
-
权限:
The permissions :
<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
我建议保存在内部存储器中的文件。这样,当用户卸载应用程序,文件被删除。你可以做这样的事情阅读:
I recommend saving the files in the internal storage. This way, when the user uninstalls the app, the files are deleted. You can do something like this to read :
File dir = getFilesDir();
File file = new File(dir, "File.txt");
try {
//Attaching BufferedReader to the FileInputStream by the help of InputStreamReader
BufferedReader bufferedReader = new BufferedReader(new FileReader(new
File(getFilesDir()+File.separator+"File.txt")));
String inputString;
s = "";
//Reading data line by line and storing it into the stringbuffer
while ((inputString = bufferedReader.readLine()) != null) {
s+=inputString + "\n";
}
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
这写:
try {
FileOutputStream fos = openFileOutput("File.txt", Context.MODE_APPEND);
for (int l = 0;l<=10;l++) {
fos.write("something".getBytes());
fos.write("\n".getBytes());
}
fos.close();
//display file saved message
} catch (Exception e) {
e.printStackTrace();
}
}
请参阅提供的链接了解详情。编码快乐!
See more details in the link provided. Happy coding!
这篇关于Android应用程序/ Android的Studio中显示C $ C $Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!