SupportWriter space ↗
REFERENCE LIBRARY

References from other publishers

Republished articles with source attribution. This collection is separate from Diary Coding’s original guides and does not display ads.

Read original guides → · Editorial policy

FOR YOUR CURIOSITY

Latest notes.

REGEX / NOTES</>↗
Regex10 Apr 2013

How to truncate a string after n number of words?

package org.kodejava.regex; public class GetNumberOfWordsFromString { public static void main(String[] args) { String text = "The quick brown fox jumps over the lazy dog."; String one = truncateAfterWords(1, text); System.out.println("1 = " + one); String two = truncateAfterWords(2, text); System.out.println("2 = " + two); String four = truncateAfterWords(4, text); System.out.println("4 = " + four); String […]

Wayan · 1 min read
SWING / NOTES</>↗
Swing10 Apr 2013

How to define JRadioButton label position?

In this code snippet you’ll see how to define JRadioButton label position. By default, the label will be displayed on the right side of the button. In the code below you will see some examples for placing the label on the left side, at the top and the bottom of the JRadioButton. To define the […]

Wayan · 2 min read
CORE API / NOTES</>↗
Core API03 Apr 2013

How to monitor file or directory changes?

package org.kodejava.io; import java.io.IOException; import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; public class FileWatchDemo { public static void main(String[] args) { try { // Creates a instance of WatchService. WatchService watcher = FileSystems.getDefault().newWatchService(); // Registers the logDir below with a watch service. Path logDir = Paths.get("F:/Temp/"); logDir.register(watcher, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE); // Monito...

Wayan · 1 min read
CORE API / NOTES</>↗
Core API03 Apr 2013

How to get the file name when using WatchService?

package org.kodejava.io; import java.io.IOException; import java.nio.file.*; import static java.nio.file.StandardWatchEventKinds.*; public class WatchServiceGetFilename { public static void main(String[] args) { try { // Create a WatchService and register the logDir path with the // WatchService for ENTRY_CREATE. WatchService watcher = FileSystems.getDefault().newWatchService(); Path logDir = Paths.get("F:/Temp"); logDir.register(watcher, ENTRY_CREATE); while (true) { WatchKe...

Wayan · 1 min read
CORE API / NOTES</>↗
Core API02 Apr 2013

How to read file using Files.newBufferedReader?

In the snippet below you’ll learn to open file for reading using Files.newBufferedReader() method in JDK 7. This method returns a java.io.BufferedReader which makes a backward compatibility with the old I/O system in Java. To read a file you’ll need to provide a Path and the Charset to the newBufferedReader() method arguments. package org.kodejava.io; import […]

Wayan · 1 min read
CORE API / NOTES</>↗
Core API02 Apr 2013

How to write file using Files.newBufferedWriter?

To open a file for writing in JDK 7 you can use the Files.newBufferedWriter() method. This method takes three arguments. We need to pass the Path, the Charset and a varargs of OpenOption. For example, in the snippet below we pass the path of our log file, we use the StandardCharsets.UTF_8 charset, and we use […]

Wayan · 2 min read
✳

Knowledge grows when shared.

Stay curious. There is always something new to learn.

Explore notes ↗
Putu Adi Guna Permana
ABOUT THE AUTHOR

Dr (C). Ir. Putu Adi Guna Permana, S.Kom., M.Kom., IPM., ASEAN Eng.

Writer and founder of Diary Coding — sharing notes, tutorials, and experiences about programming for anyone who wants to keep learning.