我有一種方法將/res/raw/
中的XML文件複製到本地存儲中。然而,它結束了複印的文件有一個附加的註釋中產生,是不是原來的XML文件中:Android原始XML文件插入註釋
<!-- From: file:/C:/Users/William/Documents/Projects/Home/KanjiFixProject/KanjiFix/src/main/res/raw/fallback_fonts.xml -->
這似乎給在那裏,當我編譯了該項目的文件存在的位置。 See here for the full file text.
什麼是導致此文本出現,我該如何防止它?以下是我使用的文件從/res/raw/
複製到磁盤的方法:
private void copyRawResourceToFile(int resource, File outputFile) throws IOException {
InputStream stream = getResources().openRawResource(resource);
FileOutputStream output = null;
byte[] buffer = new byte[1024];
int read = 0;
try {
output = new FileOutputStream(outputFile);
while ((read = stream.read(buffer)) > 0) {
output.write(buffer, 0, read);
}
output.flush();
}
finally {
stream.close();
if (output != null) {
output.close();
}
}
}
我剛剛測試了這段代碼,文件被成功複製,就像原始文件一樣,沒有額外的評論。可能是安裝了一個攔截文件副本並添加評論的應用程序?雖然我不確定是否有這樣的應用程序... –
只是爲了更加完整,我使用的是Android Studio 0.2.10,我正在使用Stock ROM在Android 4.3 Galaxy Nexus上進行測試。我猜這可能是Android Studio的一個怪癖?我的完整源代碼是開源的,並且該行絕對不存在:https://github.com/ascendedguard/android-kanji-fix/blob/master/KanjiFix/src/main/res/raw/fallback_fonts.xml –
使用Gradle構建系統從命令行編譯應用程序時(無論調試模式或釋放模式如何),這也發生在我身上。 –