如何从InputStream创建File对象,该对象是从Android中的AssetManager创建的?

时间:2016-06-01 01:42:31

标签: android nanohttpd

我在Android App中使用NanoHTTPD作为Web服务器,函数newFixedFileResponse需要传递File对象。

我在Android的文件夹资源中放置了一个index.html文件,我发现我只能通过InputStream is = am.open("index.html")访问该文件;

现在我希望创建一个基于InputStream myInputStream的File对象并将其传递给functin newFixedFileResponse,我该怎么办?谢谢!

AssetManager am = getResources().getAssets();  
InputStream myInputStream = am.open("index.html");

的index.html

<html>
<head>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
</head>

<body>
<h1>This is a.htm </h1>
<div class="MyFont">This is css font</div>
<a href="b.htm">Go to b.htm</a>
</body></html>

功能

 private Response HandleFile(String uri){
        Response response = null;
        String mimeTypeForFile = getMimeTypeForFile(uri);
        File f = new File(rootDir, uri);


        try {
            response =  newFixedFileResponse(f, mimeTypeForFile);
        }catch (Exception e){           
        }
        return response != null ? response : getNotFoundResponse();
    }

0 个答案:

没有答案
相关问题