首页 文章 精选 留言 我的

精选列表

搜索[android things],共10000篇文章
优秀的个人博客,低调大师

Android--List转换String,String转换List

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/68927553 调用方法: //字符串转成list List list; String im = "123+456+789"; list = StringToList(im); //list转字符串 String str = ListToString("要转换的List"); 封装的类: private static final String SEP1 = "#"; private static final String SEP2 = "|"; private static final String SEP3 = "="; /** * List转换String * * @param list * :需要转换的List * @return String转换后的字符串 */ public static String ListToString(List<?> list) { StringBuffer sb = new StringBuffer(); if (list != null && list.size() > 0) { for (int i = 0; i < list.size(); i++) { if (list.get(i) == null || list.get(i) == "") { continue; } // 如果值是list类型则调用自己 if (list.get(i) instanceof List) { sb.append(ListToString((List<?>) list.get(i))); sb.append(SEP1); } else if (list.get(i) instanceof Map) { sb.append(MapToString((Map<?, ?>) list.get(i))); sb.append(SEP1); } else { sb.append(list.get(i)); sb.append(SEP1); } } } return "L" + sb.toString(); } /** * Map转换String * * @param map * :需要转换的Map * @return String转换后的字符串 */ public static String MapToString(Map<?, ?> map) { StringBuffer sb = new StringBuffer(); // 遍历map for (Object obj : map.keySet()) { if (obj == null) { continue; } Object key = obj; Object value = map.get(key); if (value instanceof List<?>) { sb.append(key.toString() + SEP1 + ListToString((List<?>) value)); sb.append(SEP2); } else if (value instanceof Map<?, ?>) { sb.append(key.toString() + SEP1 + MapToString((Map<?, ?>) value)); sb.append(SEP2); } else { sb.append(key.toString() + SEP3 + value.toString()); sb.append(SEP2); } } return "M" + sb.toString(); } /** * String转换Map * * @param mapText * :需要转换的字符串 * @param KeySeparator * :字符串中的分隔符每一个key与value中的分割 * @param ElementSeparator * :字符串中每个元素的分割 * @return Map<?,?> */ public static Map<String, Object> StringToMap(String mapText) { if (mapText == null || mapText.equals("")) { return null; } mapText = mapText.substring(1); mapText = mapText; Map<String, Object> map = new HashMap<String, Object>(); String[] text = mapText.split("\\" + SEP2); // 转换为数组 for (String str : text) { String[] keyText = str.split(SEP3); // 转换key与value的数组 if (keyText.length < 1) { continue; } String key = keyText[0]; // key String value = keyText[1]; // value if (value.charAt(0) == 'M') { Map<?, ?> map1 = StringToMap(value); map.put(key, map1); } else if (value.charAt(0) == 'L') { List<?> list = StringToList(value); map.put(key, list); } else { map.put(key, value); } } return map; } /** * String转换List * * @param listText * :需要转换的文本 * @return List<?> */ public static List<Object> StringToList(String listText) { if (listText == null || listText.equals("")) { return null; } listText = listText.substring(1); listText = listText; List<Object> list = new ArrayList<Object>(); String[] text = listText.split(SEP1); for (String str : text) { if (str.charAt(0) == 'M') { Map<?, ?> map = StringToMap(str); list.add(map); } else if (str.charAt(0) == 'L') { List<?> lists = StringToList(str); list.add(lists); } else { list.add(str); } } return list; } 利用Java自身类: String abc = "aaa,bbb,ccc"; String[] arr = abc.split(","); List<String> list = java.util.Arrays.aslist(abc);

优秀的个人博客,低调大师

Android--文件夹压缩为.zip

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/64439638 package com.zipUtil; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; public class ZipUtil { public static void zip(String src, String dest) throws IOException { //提供了一个数据项压缩成一个ZIP归档输出流 ZipOutputStream out = null; try { File outFile = new File(dest);//源文件或者目录 File fileOrDirectory = new File(src);//压缩文件路径 out = new ZipOutputStream(new FileOutputStream(outFile)); //如果此文件是一个文件,否则为false。 if (fileOrDirectory.isFile()) { zipFileOrDirectory(out, fileOrDirectory, ""); } else { //返回一个文件或空阵列。 File[] entries = fileOrDirectory.listFiles(); for (int i = 0; i < entries.length; i++) { // 递归压缩,更新curPaths zipFileOrDirectory(out, entries[i], ""); } } } catch (IOException ex) { ex.printStackTrace(); } finally { //关闭输出流 if (out != null) { try { out.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } private static void zipFileOrDirectory(ZipOutputStream out, File fileOrDirectory, String curPath) throws IOException { //从文件中读取字节的输入流 FileInputStream in = null; try { //如果此文件是一个目录,否则返回false。 if (!fileOrDirectory.isDirectory()) { // 压缩文件 byte[] buffer = new byte[4096]; int bytes_read; in = new FileInputStream(fileOrDirectory); //实例代表一个条目内的ZIP归档 ZipEntry entry = new ZipEntry(curPath + fileOrDirectory.getName()); //条目的信息写入底层流 out.putNextEntry(entry); while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } out.closeEntry(); } else { // 压缩目录 File[] entries = fileOrDirectory.listFiles(); for (int i = 0; i < entries.length; i++) { // 递归压缩,更新curPaths zipFileOrDirectory(out, entries[i], curPath + fileOrDirectory.getName() + "/"); } } } catch (IOException ex) { ex.printStackTrace(); // throw ex; } finally { if (in != null) { try { in.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } @SuppressWarnings("unchecked") public static void unzip(String zipFileName, String outputDirectory) throws IOException { ZipFile zipFile = null; try { zipFile = new ZipFile(zipFileName); Enumeration e = zipFile.entries(); ZipEntry zipEntry = null; File dest = new File(outputDirectory); dest.mkdirs(); while (e.hasMoreElements()) { zipEntry = (ZipEntry) e.nextElement(); String entryName = zipEntry.getName(); InputStream in = null; FileOutputStream out = null; try { if (zipEntry.isDirectory()) { String name = zipEntry.getName(); name = name.substring(0, name.length() - 1); File f = new File(outputDirectory + File.separator + name); f.mkdirs(); } else { int index = entryName.lastIndexOf("\\"); if (index != -1) { File df = new File(outputDirectory + File.separator + entryName.substring(0, index)); df.mkdirs(); } index = entryName.lastIndexOf("/"); if (index != -1) { File df = new File(outputDirectory + File.separator + entryName.substring(0, index)); df.mkdirs(); } File f = new File(outputDirectory + File.separator + zipEntry.getName()); // f.createNewFile(); in = zipFile.getInputStream(zipEntry); out = new FileOutputStream(f); int c; byte[] by = new byte[1024]; while ((c = in.read(by)) != -1) { out.write(by, 0, c); } out.flush(); } } catch (IOException ex) { ex.printStackTrace(); throw new IOException("解压失败:" + ex.toString()); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { } } if (out != null) { try { out.close(); } catch (IOException ex) { } } } } } catch (IOException ex) { ex.printStackTrace(); throw new IOException("解压失败:" + ex.toString()); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ex) { } } } } } 调用: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Thread th = new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { ZipUtil.zip(Environment.getExternalStorageDirectory().getPath()+"/baidu", Environment.getExternalStorageDirectory().getPath()+"/baidu.zip"); ZipUtil.unzip(Environment.getExternalStorageDirectory().getPath()+"/baidu.zip", Environment.getExternalStorageDirectory().getPath()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } });th.start(); }

优秀的个人博客,低调大师

Android studio出现:Cause: error in opening zip file

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/60868487 解决办法:删除掉 ~/.gradle/wrapper/dists/ 下的文件夹,重新运行即可 参考内容: The solution that worked for me I had the luxury of comparing differences with working projects. That is how I discovered the error was due to thedistributionUrlproperty in thegradle/wrapper/gradle-wrapper.propertiesfile. In the failing project this was set likedistributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip. While in the working project this wasdistributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip. Note the difference in the version. Updating this distributionUrl in gradle-wrapper.properties to this1.11link solved the issue for me.

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册