模板:

  • 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. PAT甲级1013-1014-1015

    题目:1013 Battle Over Cities 思路:城市数也就1000, 对于每次询问暴力bfs一下看一下有多少连通块就行了.答案就是联通块数减一. #include<stdio.h&g ...

  2. Global Error Handling in ASP.NET Web API 2(webapi2 中的全局异常处理)

    目前,在Web API中没有简单的方法来记录或处理全局异常(webapi1中).一些未处理的异常可以通过exception filters进行处理,但是有许多情况exception filters无法 ...

  3. [No0000C8]英特尔快速存储IRST要不要装

    IRST (英特尔快速存储技术)Intel Rapid Storage Technology(简称IRST)又称英特尔快速存储技术. Intel Rapid Start Technolog同样是简称( ...

  4. 解决GP服务产生的结果无法自动发布为地图服务的问题

    在ArcGIS for Javascript API或REST API调用GP服务时,常常会遇到这样一种情况:GP服务运行以后,执行成功,也能够生成结果,然而结果并没有直接产生动态的地图服务供API调 ...

  5. ionic中数据进行操作后,需要直接显示改变后的数据,数据刷新

    数据分页是通过使用下拉加载,查询sqlite本地数据的数据 <ion-refresher (ionRefresh)="doTest($event)"> <ion- ...

  6. 最大似然估计(Maximum likelihood estimation)(通过例子理解)

    似然与概率 https://blog.csdn.net/u014182497/article/details/82252456 在统计学中,似然函数(likelihood function,通常简写为 ...

  7. pip list 和 pip freeze

    https://blog.csdn.net/vitaminc4/article/details/76576956 Pip’s documentation statespip     descripti ...

  8. 2018/04/25 PHP7的编译安装

    为什么要编译安装? 因为最近要学习 swoole ,想使用目前最新的 PHP7.2.4 ,但是我所在的 Ubuntu-16.04 的 apt 下只有 PHP7.0 的版本. 加上自己也想学习一下源码的 ...

  9. Master-Worker集群计算demo

    Task为要执行的任务实体类: package com.viewhigh.mdop.bi.test; /** * Created by zzq on 2017/5/11. */ public clas ...

  10. 页面调用qq

    tencent://message/?uin=516999605&Site=&Menu=yes