Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Process API
Search
Jussi Pohjolainen
April 26, 2020
Technology
1
190
Process API
Simple examples how to execute shell commands using Java
Jussi Pohjolainen
April 26, 2020
Tweet
Share
More Decks by Jussi Pohjolainen
See All by Jussi Pohjolainen
Introduction to SwiftUI V2
pohjus
0
100
Kotlin Coroutines
pohjus
0
380
Android HTTP Clients
pohjus
0
380
Android HTTP Clients - v2
pohjus
0
10
Introduction to Jetpack Compose
pohjus
1
530
Java Exceptions
pohjus
0
260
Quick Start to React - Update 2024-01-03
pohjus
2
5.5k
Java Tools
pohjus
0
180
Node.js Development with ES2015 ->
pohjus
0
3.9k
Other Decks in Technology
See All in Technology
本当のガバクラ基礎
toru_kubota
0
150
Gradle Build Scanを使ってビルドのことを知ろう potatotips #87
tomorrowkey
2
170
モーダル間の変換後の一致性とジャンル表を用いた解釈可能性の考察 ~Text-to-MusicとText-To-ImageかつImage-to-Musicを例に~
otanet
0
320
今さら聞けないDocker入門 〜 Dockerfileのベストプラクティス編
devops_vtj
21
6.2k
2024春 注目のWeb系 OSS & SaaS 3選
makies
0
200
How to Lead? Testimonial of a Lead Android Engineer
oleur
1
120
Building Dashboards as a Hobby
egmc
0
420
MLOpsの「壁」を乗り越える、LINEヤフーの Data Quality as Code
lycorptech_jp
PRO
8
680
M5stackで使用できるpHセンサの開発
shinrinakamura
1
280
IaCジェネレーターとBedrockで詳細設計書を生成してみた
tsukasa_ishimaru
4
940
コードや知識を組み込む / Incorporate Code and knowledge
ks91
PRO
0
160
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
2.1k
Featured
See All Featured
Statistics for Hackers
jakevdp
790
220k
Docker and Python
trallard
35
2.7k
Infographics Made Easy
chrislema
238
18k
What the flash - Photography Introduction
edds
64
11k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
Building Better People: How to give real-time feedback that sticks.
wjessup
356
18k
Producing Creativity
orderedlist
PRO
338
39k
Facilitating Awesome Meetings
lara
43
5.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
321
23k
Optimising Largest Contentful Paint
csswizardry
13
2.4k
Writing Fast Ruby
sferik
622
60k
Automating Front-end Workflow
addyosmani
1357
200k
Transcript
Properties API Jussi Pohjolainen
To store preferences • Simple API to • fetch •
store • key value pairs
import java.io.*; import java.util.*; class Main { public static void
main(String [] args) throws Exception { Properties prop = new Properties(); // set key and value prop.setProperty("fontSize", "24"); prop.setProperty("fontColor", "RGB(255,255,255)"); String optionalComments = "My preferences file"; prop.store(new FileWriter("./myfile.prop"), optionalComments); } }
myfile.prop #My preferences file #Sun Apr 26 10:56:55 EEST 2020
fontSize=24 fontColor=RGB(255,255,255)
Reading import java.io.*; import java.util.*; class Main { public static
void main(String [] args) throws Exception { Properties prop = new Properties(); prop.load(new FileReader("./myfile.prop")); System.out.println(prop.get("fontSize")); System.out.println(prop.get("fontColor")); } }
Storing XML import java.io.*; import java.util.*; class Main { public
static void main(String [] args) throws Exception { Properties prop = new Properties(); // set key and value prop.setProperty("fontSize", "24"); prop.setProperty("fontColor", "RGB(255,255,255)"); String optionalComments = "My preferences file"; prop.storeToXML(new FileOutputStream("./myfile.xml"), optionalComments); } }
myfile.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>My
preferences file</comment> <entry key="fontSize">24</entry> <entry key="fontColor">RGB(255,255,255)</entry> </properties>
Reading import java.io.*; import java.util.*; class Main { public static
void main(String [] args) throws Exception { Properties prop = new Properties(); prop.loadFromXML(new FileInputStream("./myfile.xml")); System.out.println(prop.getProperty("fontSize")); System.out.println(prop.getProperty("fontColor")); } }
Jackson
Jackson • Java classes to json mapping • External class
library, add dependency • You can use Jackson to save for example preferences file
Dependency <dependencies> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.10.3</version> </dependency> </dependencies>
Pojo public class Dog { private String name; public void
setName(String name) { this.name = name; } public String getName() { return this.name; } }
Main import com.fasterxml.jackson.databind.ObjectMapper; import java.io.*; class Main { public static
void main(String [] args) throws Exception { Dog spot = new Dog(); spot.setName("Spot"); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(new File("./file.json"), spot); Dog temp = objectMapper.readValue(new File("./file.json"), Dog.class); System.out.println(temp.getName()); } }