Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android中资产的传递路径_Java_Android_Chunk Templates - Fatal编程技术网

Java Android中资产的传递路径

Java Android中资产的传递路径,java,android,chunk-templates,Java,Android,Chunk Templates,我尝试在我的android项目(get at)中使用名为Chunk Templates(类似于velocity)的模板引擎。使用时,我需要访问“我的资产”文件夹中的模板文件: Theme t = new Theme("path to file"); //path getAssets()..? file:///....? Chunk c = t.makeChunk("template"); //template.chtml c.... “template.chtml”位于我的eclipse文件夹

我尝试在我的android项目(get at)中使用名为Chunk Templates(类似于velocity)的模板引擎。使用时,我需要访问“我的资产”文件夹中的模板文件:

Theme t = new Theme("path to file"); //path getAssets()..? file:///....?
Chunk c = t.makeChunk("template"); //template.chtml
c....
“template.chtml”位于我的eclipse文件夹“assets\themes\template.chtml”中 在我的设备上运行时,模板引擎会显示“找不到模板”

我必须走哪条路

您好, Hamzty

试试这个:

AssetFileDescriptor descriptor = getAssets().openFd("your file");
FileReader reader = new FileReader(descriptor.getFileDescriptor());
试试这个:

AssetFileDescriptor descriptor = getAssets().openFd("your file");
FileReader reader = new FileReader(descriptor.getFileDescriptor());

尝试
InputStream instream=getAssets().open(“file.xxx”)
从活动类访问资产文件夹中的文件

编辑:

您也可以这样尝试:


需要一点手动硬编码,但我认为它会起作用。

试试
InputStream instream=getAssets()。打开(“file.xxx”)
从活动类访问资产文件夹中的文件

编辑:

您也可以这样尝试:

需要一点手动硬编码,但我认为它会起作用。

试试这个

file:///android_asset/themes/template.chtml
试试这个

file:///android_asset/themes/template.chtml

好的,我给作者写了一封电子邮件,解决方案还没有发布,将在未来的发行版中添加。我得到了一个实验版本,其中的代码如下所示:

AndroidThemeLoader loader = new AndroidThemeLoader(getBaseContext());
Theme theme = new Theme(loader);
Chunk chunk = theme.makeChunk("test#subtest");
chunk.set("name", "Dennis");
String html = chunk.toString();
String mime = "text/html";
String encoding = "utf-8";
WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
String baseURL = null;
myWebView.loadDataWithBaseURL(baseURL, html, mime, encoding, null);

谢谢大家对我的帮助

好的,我给作者写了一封电子邮件,但解决方案尚未发布,将在未来的发行版中添加。我得到了一个实验版本,其中的代码如下所示:

AndroidThemeLoader loader = new AndroidThemeLoader(getBaseContext());
Theme theme = new Theme(loader);
Chunk chunk = theme.makeChunk("test#subtest");
chunk.set("name", "Dennis");
String html = chunk.toString();
String mime = "text/html";
String encoding = "utf-8";
WebView myWebView = (WebView)this.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
String baseURL = null;
myWebView.loadDataWithBaseURL(baseURL, html, mime, encoding, null);


谢谢大家对我的帮助

Typeface-Typeface=Typeface.createFromAsset(activity.getAssets(),“font/roboto-light.ttf”)用于获取字体,相应地更改它以使用它们。这是个好主意,但goolge说它只是用于字体…=((也是createFromAsset)下面的任何解决方案有效吗?我尝试了所有解决方案,但都无效:(
Typeface-Typeface=Typeface.createFromAsset(activity.getAssets(),“fonts/roboto-light.ttf”)
用于获取字体,相应地更改以使用主题。好主意,但goolge说它仅用于字体…=((也是createFromAsset)以下任何解决方案有效吗?我尝试了所有解决方案,但均无效:(谢谢您的回答,但我需要一个路径来实例化我的主题类新主题(字符串路径)谢谢你的回答,但我需要一个路径来实例化我的主题类新主题(字符串路径)嗨,如果我尝试这个,我会得到false…=(:File f=new File(“file:///android_asset/themes/template.chtml“”;System.out.println(f.exists());您好,如果我尝试此操作,我会得到false…=(:File f=新文件(“”)file:///android_asset/themes/template.chtml");System.out.println(f.exists());您好,谢谢您的回答-使用此方法,我可以将文件放入流中,但我的主题变量无法处理流。它需要一个字符串,如果没有该字符串,则应为chtml文件所在的路径。据我所知,无法获得绝对路径,您可以使用输入流和输出流创建
文件
我指向一个新文件。请查看区块模板文档或向作者提出此问题。是的,这可能是另一种方法,但不是最好的;)您好,谢谢您的回答-使用此方法,我可以将文件放入流中,但我的主题变量无法处理流。它需要一个字符串,如果没有该字符串,则应为chtml文件所在的路径。据我所知,无法获得绝对路径,但您可以使用输入流和输出流创建
文件指向新文件。请查看区块模板文档或向作者提出此问题。是的,这可能是另一种方法,但不是最好的;)