[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 ...
随机推荐
- url自动补全index.php
location / { index index.html index.htm index.php l.php; autoindex on; if (!-e $request_filename) { ...
- Windows Server 2008 R2远程协助选项 灰色
管理工具——〉服务器管理器——〉功能——〉添加功能 窗口中"远程服务器管理工具"下边的"远程协助"打上对钩"再点击"下一步"再 ...
- org.apache.jasper.JasperException:Unable to read TLD "META-INF/c-1_0-rt.tld" from JAR file jstl-1.2.jar
前两天把项目从eclipse EE版搬到MyEclipse中了.配置好jdk,确定build path中没有报错后,在tomcat中运行.结果,报错: org.apache.jasper.Jasper ...
- 开发人员如何从官网首页进入下载JDK历史版本
就是下面的这篇文章,好心好意提交到百度经验,希望给需要的人一个帮助,结果被拒,说有广告.呵呵,oracle和java真的需要在你百度上面做广告吗?倒是能理解,可能是外行人做的,只是看到链接就拒了,但是 ...
- JSCS: Please specify path to 'JSCS' package
JSCS: Please specify path to 'JSCS' package 1.webStrom提示: JSCS: Please specify path to 'JSCS' packag ...
- CSS3 transform 属性
CSS3 transform 属性 语法: transform: none|transform-functions; 值 描述 none 定义不进行转换. matrix(n,n,n,n,n,n) 定义 ...
- [skill][c][ld][gcc] 明确指定gcc在链接时明确使用静态库
通常,我们这样链接: gcc -o a.out -L/usr/lib/ -ltest a.o 这样它会链接动态库 libtest.so, 可是有时候我们想在静态库与动态库同时存在时,优先使用静态库. ...
- Excel--数据透视图
原文:https://ke.qq.com/course/289406 1.数据源注意项 2. 3.选中数据源操作 任意选中数据源表格中的单元格(有值得单元格),插入数据透视表 默认数据源区域就是整个表 ...
- linux关闭的时候出现异常: java.net.ConnectException: 拒绝连接 (Connection refused)
这个时候: 需要先把java进程杀死. 然后再重新启动. 杀死进程: ps -aux | grep java 然后kill -9 进程 然后再重新启动.
- 在Linux下用C语言实现短信收发
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lyserver/archive/2008/10/01/3007090.aspx 首先,我根据功能需要创建了几个头文件 ...