安卓导入web html 文件快速读写方法

安卓导入web html 文件快速读写方法,第1张

总所周知在安卓的资源文件中可以直接放入文件,webView 加载的时候可以直接调用(webview.loadUrl("file:///android_asset/"+文件名称)),

但是assets 文件不支持写入文件,如果我们要更新html 文件怎么办呢。

1、磨塌神我们可以把初始版本html 文件压缩到assets 下,然后在解压到本地文件中去。如果后面有小的更新我们只需要根据文件MD5去更新

2、如果是衫察大的更新我们只需要重新导入压缩包到assets 下面打包即可。特别注意assets 文件压缩直接最好检查一下是否包含中文,不然会解压不成功

/**/**

* 解压缩功能.

* 将zipFile文件解压到folderPath目录下.

* ZipFile 解压全部文件效率高于 ZipInputStream

* @throws Exception

*/

public static int upZipFile(File zipFile, String folderPath, ISiteFileManagetEvent event)throws IOException {

ZipFile zfile =new ZipFile(zipFile)

    Enumeration zList = zfile.entries()

    ZipEntry ze =null

    byte[] buf =new byte[1024]

    int nowLength =0

    while (zList.hasMoreElements()) {

ze = (ZipEntry) zList.nextElement()

        if (ze.isDirectory()) {

Log.e("upZipFile", ze.getName())

            String dirstr = folderPath + ze.getName()

            dirstr =new String(dirstr.getBytes("8859_1"), "GB2312")

            File f =new File(dirstr)

            f.mkdir()

continue

        }

OutputStream os =new BufferedOutputStream(new FileOutputStream(getRealFileName(folderPath, ze.getName())))

        InputStream is =new BufferedInputStream(zfile.getInputStream(ze))

        int readLen =0

        while ((readLen = is.read(buf, 0, 1024)) != -1) {

os.write(buf, 0, readLen)

        }

nowLength +=1

        event.SiteFileManagetProcess(nowLength, 201)

        is.close()

     瞎亏   os.close()

    }

event.SiteFileManagetFinishEvent("")

    if (zipFile !=null) {

boolean delete = zipFile.delete()

        Log.e("BaseFileUtil1", delete +"")

    }

zfile.close()

    return 0

}

/**

* 给定根目录,返回一个相对路径所对应的实际文件名.

*

* @param baseDir    指定根目录

* @param absFileName 相对路径名,来自于ZipEntry中的name

* @return java.io.File 实际的文件

*/

public static FilegetRealFileName(String baseDir, String absFileName) {

String[] dirs = absFileName.split("/")

    File ret =new File(baseDir)

    String substr =null

    if (dirs.length >1) {

for (int i =0i <dirs.length -1i++) {

substr = dirs[i]

            try {

//substr.trim()

                substr =new String(substr.getBytes("8859_1"), "GB2312")

            }catch (UnsupportedEncodingException e) {

e.printStackTrace()

            }

ret =new File(ret, substr)

        }

if (!ret.exists())

ret.mkdirs()

        substr = dirs[dirs.length -1]

        try {

substr =new String(substr.getBytes("8859_1"), "GB2312")

        }catch (UnsupportedEncodingException e) {

e.printStackTrace()

        }

ret =new File(ret, substr)

        return ret

    }

return ret

}

* 复制zip 压缩文件到 本地

* @param strOutFileName 本地文件路径

* @param zipName        assets 文件名称需要带文件后缀 xx.zip

* @throws IOException

*/

public static void copyBigDataToSD(Context context, String strOutFileName, String zipName)throws IOException {

InputStream myInput

    OutputStream myOutput =new FileOutputStream(strOutFileName)

    // *** 作assets 文件

    myInput = context.getAssets().open(zipName)

    byte[] buffer =new byte[1024]

    int length = myInput.read(buffer)

    while (length >0) {

myOutput.write(buffer, 0, length)

        length = myInput.read(buffer)

    }

myOutput.flush()

    myInput.close()

    myOutput.close()

}

美学批判历史文学的本质性差异和凳银同一性关联是一个古老的话题,亚桥粗好里士多德在《诗学》中写道:“两者的差别在于一叙述已发生的事,一描述可能发生的事。因此,写诗这种活动比写历史更富于哲学意味,更被严肃地对待;因为诗所描述的事带有普遍性,历史则叙述个别的事。”[17] 《三国演义》的写作主体显然没有历史和文学的区分意识,所以,小说文本没有呈现历史与文学的差异敏铅性理念,所有历史和文学的故事元素和话语表达都是被混淆界线与纠缠不清的。正是导源于先天性质的美学观念的局限,小说被涂抹成为既不是历史又不符合文学一般规定性的一个混合性文本。问题的另一方面在于,历史和文学的同一性关联在哲学意义上,它们都应该和必然地表现历史的客观规律及其偶然性结构,换言之,历史和文学都必然共同地隐含着历史理性和辩证逻辑。[18]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/12241339.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-22
下一篇 2023-05-22

发表评论

登录后才能评论

评论列表(0条)

保存