ZIP AND GZIP / CATATAN</>↗Zip and GZIP25 Mei 2008
This example demonstrate how to use CheckedOutputStream for creating a checksum of a zip file. Checksum can be used to detect whether a data was corrupted during a transmission process to a remote machine. package org.kodejava.util.zip; import java.io.*; import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import java.util.zip.CheckedOutputStream; import java.util.zip.Adler32; public class ZipWithChecksum { public static void […]
ZIP AND GZIP / CATATAN</>↗Zip and GZIP20 Mei 2008
In this example we use the java.util.zip.ZipFile class to decompress and extract a zip file. package org.kodejava.util.zip; import java.util.zip.ZipFile; import java.util.zip.ZipEntry; import java.util.Enumeration; import java.io.*; public class ZipFileUnzipDemo { public static void main(String[] args) throws Exception { String zipName = "data.zip"; ZipFile zip = new ZipFile(zipName); Enumeration<? extends ZipEntry> enumeration = zip.entries(); while (enumeration.hasMoreEleme...
ZIP AND GZIP / CATATAN</>↗Zip and GZIP16 Mei 2008
The code below shows how to decompress and extract files from a zip archive. In the example we use the java.util.zip.ZipInputStream class. package org.kodejava.util.zip; import java.io.*; import java.util.zip.ZipInputStream; import java.util.zip.ZipEntry; public class UnzipDemo { public static void main(String[] args) { String zipName = "data.zip"; try (FileInputStream fis = new FileInputStream(zipName); ZipInputStream zis = new ZipInputStream(new […]
CORE API / CATATAN</>↗Core API15 Mei 2008
The following code can be used to validate if a string contains a valid date information. The pattern of the date is defined by the java.text.SimpleDateFormat object. When the date is not valid a java.text.ParseException will be thrown. package org.kodejava.text; import java.text.SimpleDateFormat; import java.text.ParseException; public class DateValidation { public static void main(String[] args) { SimpleDateFormat […]
CORE API / CATATAN</>↗Core API13 Mei 2008
To get Java Home directory we can obtain it from system properties using the java.home key. package org.kodejava.lang; public class JavaHomeDirectory { public static void main(String[] args) { String javaHome = System.getProperty("java.home"); System.out.println("JAVA HOME = " + javaHome); } } On my computer this code give me the following output: JAVA HOME = C:\Program Files\Java\jdk-17
CORE API / CATATAN</>↗Core API10 Mei 2008
This example show you how to get operating system active user’s login name. We can obtain the username of current user by reading system properties using the user.name key. package org.kodejava.lang; public class GettingUserName { public static void main(String[] args) { String username = System.getProperty("user.name"); System.out.println("username = " + username); } }