模板:

  • 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. ABP之事件总线(2)

    在上一篇文章中,我们复习了一下事件的经典的发布订阅模式,同时对是事件源和时间处理逻辑进行抽象统一,用起来也没有问题.但是还是有很多的问题,比如说我们Handle方法其实是违背了单一性的原则的,里面混杂 ...

  2. 新复制行绑定JQuery.autocomplete事件

    在工作中经常需要生成动态增加行的表格,此次需要对表格中的文本框绑定autocomplete功能 操作流程: 表格初始时只有一行,当页面加载时执行先执行一次增加行功能,将行增加到10行 在$(funct ...

  3. 初级ai思维导图,基础人工智能设计图

    2017年2月8日09:35:46 仅供代码和逻辑设计图纸,只提供一个参考设计,后面可能会更新具体实施说明

  4. Django:环境搭建

    django环境配置 1.安装django pip install django #安装指定版本 pip install -v django==1.8.2 通过python shell查看版本,返回版 ...

  5. es6/ts for in/ for of

    for in 是es6之前就有的循环下标的方式 for of 是typescript的循环对象或者数组中值的方式,但是不能循环普通的对象,需要通过和Object.keys()搭配使用,如果循环普通对象 ...

  6. C和C指针小记(八)-操作符、左值右值

    1.移位操作符 移位操作符分为左移操作符(<<)和右移操纵符(>>) 对于无符号数:左右位移操作都是逻辑位移 对于有符号数:到底是采用逻辑位移还是算术位移取决于编译器.如果一个 ...

  7. PHP之二维数组根据某个下标排序

    function arraySortByElements($array2sort,$sortField,$order,$iscount=false) { $functionString=' if (' ...

  8. [development][libconfig] 配置文件库

    以前,一直用ini的配置文件. 简单清晰但是不灵活. 换一个: 试试libconfig 主页:  http://www.hyperrealm.com/oss_libconfig.shtml githu ...

  9. Scaleform Gfx的Demo

    转载:http://www.xuebuyuan.com/2167614.html 新建一个Demo工程时,编译之前有一些VS的配置是必须的,在Debug和Release下,工程必须包括: $(GFXS ...

  10. 安装多个java后,java版本不对

    参考资料: https://www.cnblogs.com/Kidezyq/p/5781131.html 主要原因是javac -version是由JAVA_HOME指定的路径中的java版本来决定的 ...