模板:

  • 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. git 搭建本地仓库

    文档 创建仓库 mkdir project cd project/ git init git remote add origin /d/project/.git // 仓库创建好了 echo hell ...

  2. callback 模式

    回调,是一种机制,同时也是一种设计模式. 我们定义一个函数,让能够回调 import _products from './products.json' const TIMEOUT = 100 cons ...

  3. Tif文件合并类

    using System; using System.Collections; using System.Collections.Generic; using System.Drawing; usin ...

  4. [No0000158]思维模型1-20

    [No0000158]思维模型1-20.7z 思维模型No1|第一性原理 第一原理(又叫第一性原理)是个今年很火的概念,最早由亚里士多德提出,它相当于数学中的公理,即在每一个系统的探索中,存在第一原理 ...

  5. 【每日一题】 UVA - 340 阅读理解+模拟

    https://cn.vjudge.net/problem/UVA-340 题目很难读,差不多读了两天 意思是给你一个n个数的数列,然后有m个询问,每个询问也是一个n个数的数列,让你输出两个数:一个是 ...

  6. hash_map

    点开一道第是自己oj的第440大关,想a了,一直想却无果,学长一句点醒,开始写hash. 关于这道题呢很无语了,两天卡在这上面,而且有些dalao不到20min就a了.我太菜了. 所以要深入讨论这道题 ...

  7. day5_递归调用

    #递归的意思,函数自己调用自己#递归最多递归999次#递归的效率没有循环高 实例1-递归调用: count = 0 def say(): global count count += 1 print(' ...

  8. fiddler4如何只抓取指定浏览器的包

    在实际工作中,常常会抓取浏览器的数据,其加载的数据较多,不好区分,不知道其是哪个是需要抓取的数据,所以就需抓取指定浏览器的数据,这样就能很清晰知道数据的来源. 步骤一: 打开fiddler4,再打开浏 ...

  9. adg的数据传输应用三大模式转换

    1.最大可用性模式(Maximum Availability) 1)该模式提供了仅次于"最大保护模式"的数据保护能力: 2)要求至少一个物理备库收到重做日志后,主库的事务才能够提交 ...

  10. LeetCode 590 N-ary Tree Postorder Traversal 解题报告

    题目要求 Given an n-ary tree, return the postorder traversal of its nodes' values. 题目分析及思路 题目给出一棵N叉树,要求返 ...