[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 ...
随机推荐
- 洛谷P1403 约数研究【思维】
题目:https://www.luogu.org/problemnew/show/P1403 题意: 定义$f(n)$为n的因子个数.给定一个数n,求$f(1)$到$f(n)$之和. 思路: 最直接的 ...
- 洛谷P1118 数字三角形【dfs】【STL】
题目链接:https://www.luogu.org/problemnew/show/P1118 题意: 1~n的一个排列,相邻的两项加起来得到下一行. 现在给定最后一行的数字,问最初的1~n的排列是 ...
- 鸡头兔头共20,脚56,鸡兔各有多少?算法实 php现版
//$x 鸡头 //$y 兔头 for ($x = 0; $x <= 20; $x++) { for ($y = 0; $y <= 20; $y++) { if (($x + $y == ...
- 通过Jenkins在IIS上布署站点
当需要在多台服务器的IIS上布署站点时,如果纯粹靠人工手动完成此任务的话,过于低效,而借助Jenkins之类的自动化工具,则可以极大提升工作效率. 以下便是Jenkins Pipeline所使用的脚本 ...
- AutoFac Ioc依赖注入容器
本文原著:牛毅 原文路径 http://niuyi.github.io/blog/2012/04/06/autofac-by-unit-test/ 理解IOC容器请看下图: 没有使用IOC容器的情况 ...
- sql join 语句的小总结
CREATE TABLE Persons ( id INT PRIMARY KEY, LastName CHAR() NOT NULL, FirstName VARCHAR (), address V ...
- [No0000174]Spring常用注解(收藏大全)
Spring部分 1.声明bean的注解 @Component 组件,没有明确的角色 @Service 在业务逻辑层使用(service层) @Repository 在数据访问层使用(dao层) @C ...
- Elasticsearch 2.3.3 JAVA api说明文档
原文地址:https://www.blog-china.cn/template\documentHtml\1484101683485.html 翻译作者:@青山常在人不老 加入翻译:cdcnsuper ...
- Vue 超快速学习
Vue 超快速学习 基础知识: 1.vue的生命周期: beforeCreate/created. beforeMount/mounted. beforeUpdate/updated. beforeD ...
- 原来的ALL IN ONE架构,快速的演进成为SOA架构
原来的ALL IN ONE架构,快速的演进成为SOA架构 京东服务市场高并发下SOA服务化演进架构 原创: 张俊卿 京东技术 今天