[Java] Frequently used method or solutions for issues
模板:
- 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 here. copy(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 here. Files.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的更多相关文章
- [JavaScript] Frequently used method or solutions for issues
Get the file name from the file path Solution: var fileName = fullPath.replace(/^.*[\\\/]/, ''); // ...
- [CSS] Frequently used method or solutions for issues
Stick button in right side in html Solution: //In the html <div class="float__button" & ...
- [Python] Frequently used method or solutions for issues
Web Scraping爬虫 for Mac urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] cer ...
- JAVA深入研究——Method的Invoke方法。
在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用父类的对象也会报错,虽然这是很符合多态的现象,也符合java的动态绑定规范,但还是想弄懂java ...
- Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针
Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针 1.1. java方法引用(Method References) 与c#委托与脚本语言js ...
- java.lang.reflect.Method
java.lang.reflect.Method 一.Method类是什么 Method是一个类,位于java.lang.reflect包下. 在Java反射中 Method类描述的是 类的方法信息, ...
- JAVA深入研究——Method的Invoke方法
http://www.cnblogs.com/onlywujun/p/3519037.html 在写代码的时候,发现Method可以调用子类的对象,但子类即使是改写了的Method,方法名一样,去调用 ...
- java反射机制 + Method.invoke解释 getMethod + 反射理解
功能: 通过读取另一个Dll去创建一个控件(Form,Button,TextBox,DataGridView),然后对当中一些属性进行检查. 创建控件的大致流程是,Assembly->Modul ...
- Java 反射机制[Method反射]
Java 反射机制[Method反射] 接着上一篇Java 反射机制[Field反射],通过调用Person类的setName方法将obj的name字段的Value设置为"callPerso ...
随机推荐
- 【Vue】---编写Vue插件流程---【巷子】
一.在Vue中编写插件流程 1.创建组件 components/message.vue <template> <div class="message" v-if= ...
- php 逗号 explode分割字符串 或 implode组装成字符串
php 逗号 分割字符串 介绍两个函数给你 <?php //利用 explode 函数分割字符串到数组 $source = "hello1,hello2,hello3,hello4,h ...
- 秒秒钟提高办公技巧的6个Excel技巧
一.职工身份证号码是否登记重复(=IF(COUNTIF(B2:B13,B2&"*")>1,"重复","")) 职工列表人数众多 ...
- PAT甲级1075 PAT Judge
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...
- Ubuntu下eclipse中运行Hadoop时所需要的JRE与JDK的搭配
第一组: Eclise 版本:Indigo,Service Release 1 Build id:20110916-0149 Window-->Preferences -->Compile ...
- POJ 1655 - Balancing Act - [DFS][树的重心]
链接:http://poj.org/problem?id=1655 Time Limit: 1000MS Memory Limit: 65536K Description Consider a tre ...
- [No000010E]Git7/9-标签管理
发布一个版本时,我们通常先在版本库中打一个标签(tag),这样,就唯一确定了打标签时刻的版本.将来无论什么时候,取某个标签的版本,就是把那个打标签的时刻的历史版本取出来.所以,标签也是版本库的一个快照 ...
- tensorRT 构建推理引擎
- vue中的provide/inject的学习
在 Vue.js 的 2.2.0+ 版本中添加加了 provide 和 inject 选项.用于父级组件向下传递数据.provide/inject:简单的来说就是在父组件(或者曾祖父组件)中通过pro ...
- debian安装nodejs
https://nodejs.org/en/download/ 二进制安装 sudo wget https://nodejs.org/dist/v10.15.1/node-v10.15.1-linux ...