[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 ...
随机推荐
- spring事务实现原理
实现原理 本质 如果你用过Spring AOP,那么理解注解事务就十分简单了.事务注解本质上实在事务方法加入一个Around切面,在方法开始前开始事务,在抛出异常后回滚事务.使用简单伪代码可以简单理解 ...
- spark on yarn 无法提交任务问题
java.lang.NoClassDefFoundError: com/sun/jersey/api/client/config/ClientConfig spark任务提交出错. 原因: spark ...
- php实现简单消息发送+极光推送系统
前几天刚写完的一个东西,写的比较简单,没有使用其他插件,原生php+计划任务实现 极光推送的代码 /* $receiver="registration_id" : [ " ...
- 各种可再发行组件包Redistributable及framework 下载
安装包名称 版本号 下载地址 Visual C++ 2005 Redistributable Package (x64) 下载 Visual C++ Redistributable Package ...
- LeetCode 4 - 两个排序数组的中位数 - [分治]
题目链接:https://leetcode-cn.com/problems/median-of-two-sorted-arrays/description/ 给定两个大小为 m 和 n 的有序数组 n ...
- Java NIO 与 IO之间的区别
概述 Java NIO提供了与标准IO不同的IO工作方式: Channels and Buffers(通道和缓冲区):标准的IO基于字节流和字符流进行操作的,而NIO是基于通道(Channel)和缓冲 ...
- day3:数据类型 str
1,int 一个数字占用的bit数目 i = 2 print(i.bit_length()) i = 3 print(i.bit_length()) i = 5 print(i.bit_length( ...
- linux添加新硬盘
1.添加新磁盘 2.fdisk -l查看磁盘被识别的名称 3.如果输入fdisk -l命令没有找到新的磁盘,按下面步骤操作 1)进入到cd /sys/class/scsi_host/ 2)echo & ...
- nvm npm node
npm init/install 语义版本号分为X.Y.Z三位,分别代表主版本号.次版本号和补丁版本号.当代码变更时,版本号按以下原则更新. 如果只是修复bug,需要更新Z位. 如果是新增了功能,但是 ...
- [security] security engine things
1. luarock luarock 之于 lua,就好比 pip 之于 python https://luarocks.org/ 2. lua的库 [root@base package]# ls ...