模板:

  • 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. python爬虫之真实世界中的网页解析

    Request和Response Request是我们平常浏览网页,向网站所在的服务器发起请求,而服务器收到请求后,返回给我们的回应就是Response,这种行为就称为HTTP协议,也就是客户端(浏览 ...

  2. ABP之展现层(Datatables分页)

    在前面的随笔中,已经介绍了ABP的增删改查的操作,但是对于查询的数据并没有进行分页,只是进行粗糙的展示,今天的随笔中将摸索进行分页展示.这里打算使用的分页插件是DataTables,这是一款比较强大的 ...

  3. Jexus 安装asp.net mvc EF 项目引发的错误总

    1.Linux 中的文件路径问题(配置文件路径),必须使用左斜杆 “/” 2.MVC 看 View/Web.config 下的配置文件中版本不对报错,如下: Could not locate Razo ...

  4. 文本分类学习 (十)构造机器学习Libsvm 的C# wrapper(调用c/c++动态链接库)

    前言: 对于SVM的了解,看前辈写的博客加上读论文对于SVM的皮毛知识总算有点了解,比如线性分类器,和求凸二次规划中用到的高等数学知识.然而SVM最核心的地方应该在于核函数和求关于α函数的极值的方法: ...

  5. 汇编debug工具详解

    关于debug工具里的各个指令的用法 debug调试工具详解: r:可以查看,和改变寄存器中的内容具体用法:·直接输入r的时候,回车显示当前指向内存单元中所有寄存器中的内容,并将所指机器码翻译成汇编指 ...

  6. nowcoder 211E - 位运算?位运算! - [二进制线段树][与或线段树]

    题目链接:https://www.nowcoder.com/acm/contest/211/E 题目描述 请实现一个数据结构支持以下操作:区间循环左右移,区间与,区间或,区间求和. 输入描述: 第一行 ...

  7. HDU 1002 - A + B Problem II - [高精度]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...

  8. java获取文件的路径问题

    java获取文件的路径问题 在java中读取读取文件,经常因为路径的问题找不到,此文用于记录如何定位文件的简单方法. 本基于springboot做的测试,主要是构建工程方便,所用的方法都是JDK中的方 ...

  9. 用SignalTap进行硬件仿真

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

  10. [daily][CentOS][SELinux]用key免登陆不成功,原来是SElinux在搞事情

    为了提高效率,一般情况下,会把公钥放到sshd主机的 $HOME/.ssh/authorized_keys 文件内. 把私钥放在client的 $HOME/.ssh/ 下. 然后就可以免密登录了.然而 ...