Delete the Contents of a File in Java Without Deleting It
Learn to delete the contents of a file in Java without deleting it, with Files.write, FileChannel.truncate and writers, plus partial truncation.
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
Learn to delete the contents of a file in Java without deleting it, with Files.write, FileChannel.truncate and writers, plus partial truncation.
Write a byte array to file in Java with Files.write, FileOutputStream and Files.copy, covering overwrite, append, parent folders and atomic writes.
Java streams tutorial hub with every Stream API guide grouped by task, from creating and filtering streams to collectors, sorting, numbers and debugging.
Read a specific line from a file in Java by line number with Files.lines(), readAllLines() or BufferedReader, handle missing lines and index large files.
Rename or move a file in Java with Files.move(), replace targets, use ATOMIC_MOVE, move folders across disks and avoid File.renameTo() pitfalls.
Get the file size in Java with Files.size(), compute a directory size with Files.walk(), convert bytes to KB, MB and GB, and check free disk space.
Learn the Java Cleaner API with a native memory example, the mistakes that stop cleanup, and how to migrate deprecated finalize() code in Java 25.
Primitive type streams in Java with IntStream, LongStream and DoubleStream, covering creation, sum and average, overflow, summary statistics and boxing.
How to work with dates and times in Java using java.time: a tested quick example, a table of which class to use when, and every date-time tutorial grouped by task.
Add or subtract hours, minutes and seconds in Java with LocalDateTime, ZonedDateTime, Instant and Duration, including DST changes and midnight rollover.
Get the year, month and day from a date in Java with getYear(), getMonthValue() and getDayOfMonth(), plus month names, time zones and YearMonth.
Set the JVM default time zone with -Duser.timezone, TZ or TimeZone.setDefault(). Learn the precedence, the GMT fallback and Docker and Kubernetes setup.
Get the day of week from a date in Java with getDayOfWeek(), read its number, handle time zones and strings, and convert java.util.Date values.
Get the start and end of day in Java with atStartOfDay(zone) and LocalTime.MAX, handle days that skip midnight and select a day with a half-open range.
ZonedDateTime vs OffsetDateTime in Java. See how each handles DST, which one to store in a database or send in JSON, and how to convert between them.
Format milliseconds as hours, minutes and seconds text in Java with Duration toHours() and toMinutesPart(), with days, negatives and DurationFormatUtils.
Localized date format in Java with DateTimeFormatter, FormatStyle and Locale. Show timestamps in the user’s time zone and use ofLocalizedPattern().
Java arrays explained with memory layout, default values, rules and the Arrays class, plus every array tutorial grouped by task, from copy to conversion.
Learn why ArrayStoreException happens with covariant arrays, System.arraycopy() and toArray(), how to read its message, and how to fix and prevent it.
Calculate the sum and average of an array in Java with a loop or IntStream, and avoid integer division, int overflow and empty-array traps.
Convert list to array in Java with the three toArray() methods, get an int[] from a list of Integer, and turn arrays back into lists with asList().
Convert a Java stream to array form with toArray() and a generator, and arrays to streams with Arrays.stream(), including int[], ranges and 2D arrays.
Learn to remove an element from an array in Java by index, value or condition with System.arraycopy(), streams, ArrayList and ArrayUtils.
Convert int[] to Integer[] in Java with boxed() and back with mapToInt(), handle null elements, long, double and char arrays, and use ArrayUtils.
Learn to split an array in Java at an index, into halves, into fixed-size chunks or N parts with Arrays.copyOfRange(), loops and Java 24 gatherers.
Learn to concatenate two arrays in Java with System.arraycopy(), Arrays.copyOf(), streams, ArrayUtils and Guava, for primitive and object arrays.
Check if two arrays are equal in Java with Arrays.equals(), deepEquals(), mismatch() and compare(), and fix array equality in records, sets and tests.
Check if an array is sorted in Java by comparing neighbors, with noneMatch(), a Comparator, case-insensitive strings, ArrayUtils and Guava.
Find the top N elements in an array in Java by sorting a copy, with sorted().limit(), a PriorityQueue min-heap or Guava, for numbers and objects.
Find the max and min in an array in Java with one loop, IntStream max() and min(), summaryStatistics() or a Comparator, plus empty arrays and NaN.
Java arrays have a fixed length, so we resize an array by copying it into a new one with Arrays.copyOf(). Learn the default values, the alias trap, inserting with System.arraycopy(), resizing 2D arrays and when an ArrayList fits better.
Learn to reverse an array in Java in place with a swap loop, into a new array, with Collections.reverse() and List.reversed(), and avoid the int[] trap.
Learn to declare and initialize an array in Java with new, array initializers, Arrays.fill(), setAll(), streams and 2D arrays, plus all default values.
Java tutorial for beginners on Java 25. Install the JDK, run a first program and follow a 12-step learning path plus an index of every Java topic.
Sorting in Java for arrays, lists, maps, sets and streams with Comparable, Comparator chains, null handling, Collator and the common sorting mistakes.
Learn Flogger fluent logging in Java with version 0.9, backends, rate limiting, lazy arguments and stack traces, compared with the SLF4J 2 fluent API.
Learn Java stream sort with null values using Comparator.nullsFirst() and nullsLast(), for null elements and null fields, and avoid the reversed() trap.
Java new features from Java 8 to Java 27 in one place, with release dates, LTS versions, preview and final status per feature, and links to examples.
Learn how the Java string constant pool works, why it is in the heap since Java 7, how String.intern() behaves and when string deduplication saves memory.
Create a Java enum with multiple values per constant, read them with getters, and find the constant from any value with a cached map and Optional.
Get object with max date from a Java list with Stream.max() and Comparator.comparing(). Covers min date, empty lists, null dates, ties and max per group.
Check if a date is a weekend in Java with DayOfWeek and EnumSet, support Friday-Saturday weekends, time zones and weekend pricing examples.
Java EdDSA example with Ed25519 and Ed448. Generate keys, sign and verify messages, save and load keys, and compare EdDSA with ECDSA, RSA and ML-DSA.
Learn sealed classes and interfaces in Java with permits, final, sealed and non-sealed subclasses, records, exhaustive switch and the reflection API.
Java FileWriter explained with constructors, write and append methods, append mode, the UTF-8 default since Java 18, flush, close and the alternatives.
Java InputStreamReader decodes bytes from an InputStream into characters. Learn charsets, read methods, malformed input, closing rules and alternatives.
Learn the Java FileReader class with UTF-8 charset constructors, char[] and line reading, error handling and when to use Files.newBufferedReader instead.
Install Java on 64-bit Windows with JDK 25 using the MSI, ZIP or winget, set JAVA_HOME and Path, verify java -version and check 32-bit vs 64-bit.
Java Hello World program for Java 25 and older versions, with javac and java commands, real output, a line-by-line walkthrough and fixes for common errors.
Learn to read a file from the classpath in Java, how class loaders resolve names, Class vs ClassLoader, context class loader, JARs and modules.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.