模板:

  • Split string into parts based on new line in java

    Solution:   Reference is here.

        1)

  • get out of the first part of a string until meet "<"

    Solution:   Reference is public String[] split(String regex).

        1)  s = "boo:and:foo";     String[] result = s.split(":") ; => {"boo", "and", "foo"}

        2)  s = "boo:and:foo";     String[] result = s.split(":", 2) ; => {"boo", "and:foo"}

        3)  s = "boo.and.foo";     String[] result = s.split("\\.", 2) ; => {"boo", "and.foo"}

  • Split string into parts based on new line in java

    Solution:   Reference is here.

        1)

String lines[] = string.split("\\r?\\n");
  • Convert Long in int in java

    Solution:

        1)

int result = (int) longVar;
  • Copy file to another folder in java

    Solution:    Reference is herecopy(Path source, Path target)

        1)

Path source = Paths.get("/Users/apple/Desktop/test.rtf");
Path destination = Paths.get("/Users/apple/Desktop/copied.rtf"); Files.copy(source, destination);
  • File into a String in java

    Solution:    Reference is hereFiles.readAllBytes(Path source)

        1)

String filePath = "c:/temp/data.txt";

String content = new String ( Files.readAllBytes( Paths.get(filePath) ) );
  • Path String to File in java

    Solution:

        1)

String filePath = "c:/temp/data.txt";

File file = new File (filePath );
  • Join path in java

    Solution:   Reference is here.

        1) Use Paths.get(String parentPath, args)

import java.nio.file.Path;
import java.nio.file.Paths;
Path currentPath = Paths.get(System.getProperty("user.dir"));
Path filePath = Paths.get(currentPath.toString(), "data", "foo.txt");

output is "

/Users/user/coding/data/foo.txt

"

        2) Use File(String parentPath, fileName)

import java.io.File
File file = new File(parentPath, fileName);
System.out.println(file.getAbsolutePath());
  • Get epoch time in java (present a unique Id by numbers if the time is not in the same ms)

    Solution:   Reference is here.

        1)

long epoch = System.currentTimeMillis();
String Id = Long.toString(epoch);
  • Create a path from String in java

    Solution:   Reference is here.

        1)

import java.nio.file.Paths;
Path path = Paths.get(textPath);

[Java] Frequently used method or solutions for issues的更多相关文章

  1. [JavaScript] Frequently used method or solutions for issues

    Get the file name from the file path Solution: var fileName = fullPath.replace(/^.*[\\\/]/, ''); // ...

  2. [CSS] Frequently used method or solutions for issues

    Stick button in right side in html Solution: //In the html <div class="float__button" & ...

  3. [Python] Frequently used method or solutions for issues

    Web Scraping爬虫 for Mac urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] cer ...

  4. JAVA深入研究——Method的Invoke方法。

    在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用父类的对象也会报错,虽然这是很符合多态的现象,也符合java的动态绑定规范,但还是想弄懂java ...

  5. Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针

    Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针   1.1. java方法引用(Method References) 与c#委托与脚本语言js ...

  6. java.lang.reflect.Method

    java.lang.reflect.Method 一.Method类是什么 Method是一个类,位于java.lang.reflect包下. 在Java反射中 Method类描述的是 类的方法信息, ...

  7. JAVA深入研究——Method的Invoke方法

    http://www.cnblogs.com/onlywujun/p/3519037.html 在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用 ...

  8. java反射机制 + Method.invoke解释 getMethod + 反射理解

    功能: 通过读取另一个Dll去创建一个控件(Form,Button,TextBox,DataGridView),然后对当中一些属性进行检查. 创建控件的大致流程是,Assembly->Modul ...

  9. Java 反射机制[Method反射]

    Java 反射机制[Method反射] 接着上一篇Java 反射机制[Field反射],通过调用Person类的setName方法将obj的name字段的Value设置为"callPerso ...

随机推荐

  1. ajax 获取服务器返回的XML字符串

    前台 解析失败不会抛出任何异常, 只会返回一个给定的错误文档 let l = console.log let http = ajanuw.create({ uri: 'http://localhost ...

  2. ngxs 状态管理器

    官网文档 ng6,rxjs6.0.0,ngxs3.0.1 λ ng new ngxs --style=styl --routing --skip-install λ cd ngxs λ yarn λ ...

  3. 熟悉ROS系统中的话题

    描述:这篇教程主要讲解ROS系统中的话题及rostopic和rqt_plot等命令工具: 1. Setup安装1.1 roscore 首先确保roscore已经启动运行,打开一个新的命令终端,输入如下 ...

  4. cc2650 7x7封装更换为 5X5 4x4

    https://www.deyisupport.com/question_answer/wireless_connectivity/bluetooth/f/103/t/104028.aspx 解决方案 ...

  5. Away3D引擎学习入门笔记

    (1). 准备工作,一些必须知道的东西 (创建时间:2014-06-05) A.必要的开发语言基础.至少要懂点ActionScript 3.0语法(ActionScript 3.0语法及API参考), ...

  6. Spark安装部署(local和standalone模式)

    Spark运行的4中模式: Local Standalone Yarn Mesos 一.安装spark前期准备 1.安装java $ sudo tar -zxvf jdk-7u67-linux-x64 ...

  7. Ubuntu16.04LTS卸载软件的命令

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  8. Adobe Flex初记

    公司项目要用Flex,之前没有接触过,菜鸟只好白手起家,把项目拉下来的同时配置下Flex的环境,以下是一篇参考: http://blog.sina.com.cn/s/blog_4c4a24db0100 ...

  9. spark学习笔记3

    Spark 支持在集群范围内将数据集缓存至每一个节点的内存中,可避免数据传输,当数据需要重复访问时这个特征非常有用,例如查询体积小的“热”数据集,或是运行如 PageRank 的迭代算法.调用 cac ...

  10. spark学习笔记2

    SparkContext代表和一个集群的连接 在shell中SparkContext是自动创建好的,就是sc