java 如何将Android中的文件写入raw文件夹?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11628058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to write a file in Android to the raw folder?
提问by dorien
I think this is a pretty basic question.
我认为这是一个非常基本的问题。
I am currently writing a file like this:
我目前正在写一个这样的文件:
File output = new File("exampleout.mid");
Now, I want to write the file to ../myproject/res/raw
现在,我想将文件写入 ../myproject/res/raw
I read I could do it by putting the complete url in the "". BUT. Since this is an Android app. What is the full url? I don;t have to write /home/.../myproject/...?
我读到我可以通过将完整的网址放在“”中来做到这一点。但。由于这是一个Android应用程序。什么是完整网址?我不必写 /home/.../myproject/...?
Is the solution:
解决方法是:
File output = new File("/res/raw/exampleout.mid");
Or do I need a higher url structure?
还是我需要更高的网址结构?
Sorry about asking this simple question, but since I use an Android emulator, I cannot check if the file is actually in the right place.
很抱歉问这个简单的问题,但由于我使用的是 Android 模拟器,因此我无法检查该文件是否确实位于正确的位置。
回答by Andro Selva
You cannot write a file to raw folder. Its read-only. Precisely you can't modify anything contained within "Res" folder on the fly.
您不能将文件写入原始文件夹。它是只读的。确切地说,您无法即时修改“Res”文件夹中包含的任何内容。
Check this out, https://stackoverflow.com/a/3374149
回答by Moreno
If you want to use iText on Android or the Google App Engine, you need to use iTextG.
如果您想在 Android 或 Google App Engine 上使用 iText,则需要使用 iTextG。
dependencies {
compile 'com.itextpdf:itextg:5.5.10'
}
Source: iText Official Site
来源:iText 官网