Basic File Manipulation With Java

Accessing files with Java is easy. With this easy to follow tutorial you will learn how to perform basic file operations in Java. Reading, writing, appending, and random file access are covered. Along with an introduction to file locking.

Sponsored Links:

Related Topics

Java Configuration File API
This is a simple Java Configuration file API. It provides methods for reading key-value pairs from a file. The main benefit over using Java's standard Properties class is support for nested array configuration values. This implementation is inspired by, but somewhat more basic than libconfig, a very useful C/C++ Configuration File Library.


How to Create File and Directory
In this Java File Tutorial we will basics of File and Directory in Java, How to Create File and Directory in Java, Utility methods provided by File API and Common Exception or Error you will face during File and Directory Creation or access time. Creating File is different than creating Thread in java as you don't have to implement any interface for making a Class as File in Java.


String Manipulation: The String Class
String manipulation forms the basis of many algorithms and utilities such as text analysis, input validation, and file conversion. This tutorial explores some of the needed basics. Unless otherwise noted, the following classes are contained in the java.lang library.


Primitive Types
Primitive types are the most basic data types available within the Java language; these include boolean, byte, char, short, int, long, float and double. These types serve as the building blocks of data manipulation in Java. Such types serve only one purpose — containing pure, simple values of a kind. Because these data types are defined into the Java type system by default, they come with a number of operations predefined. You can not define a new operation for such primitive types. In the Java type system, there are three further categories of primitives:


2 solution of java.lang.OutOfMemoryError in Java
Every one in java development face java.lang.OutOfMemoryError now and then, OutOfMemoryError in Java is one problem which is more due to system's limitation (memory) rather than due to programming mistakes in most cases though in certain cases you could have memory leak which causing OutOfMemoryError. I have found that even though java.lang.OutOfMemoryError is quite common basic knowledge of its cause and solution is largely unknown among junior developers. In this article we will explore what is java.lang.OutOfMemoryError; Why OutOfMemoryError comes in Java application, different type of OutOfMemoryError and How to fix OutOfMemoryError in Java. This article is purely meant to provide basic knowledge of java.lang.OutMemoryError and won't discuss profiling in detail.


How to make hidden files in Java Program with Example
we will see how to hide file in Java or make hidden file in Java. As we said File API in Java doesn’t provide any method to make a file hidden in Java but still you can apply some quick tricks to hide files from Java program. Like in Unix environment any file whose names begin with dot (.) is hidden so you can name your file starting with dot (.) and your File will be hidden in Linux or Unix Environment.


How to read XML file in Java – (DOM Parser)
Here’s an example to show you how to read a XML file in Java via DOM XML parser. The DOM interface is the easiest XML parser to understand, and use. It parses an entire XML document and load it into memory, modeling it with Object for easy traversal or manipulation.


File Handling in Java
A look at the file handling methods that Java provides, and an introduction to the complex I/O system that comes packaged in java.io. Read This Useful Java Tutorial


How to resolve java.lang.ClassNotFoundException
In this java tutorial we will see what is ClassNotFoundException in java, what is real cause of it and how to fix it along with some more frequent and infamous examples of java.lang.ClassNotFoundException in Java or J2EE, Don’t mistake this exception with NoClassDefFoundError in Java which is also due to incorrect classpath in Java. Though both of them are related to missing class file when Java tries to load class in Java they are completely different to each other. Correct understanding of When class is loaded in Java and How Classpath works is must to troubleshoot and fix this error quickly.


How to read and write in text file
Reading and writing from file in Java is very simple once you are familiar with readers, streams, input stream and output stream in Java. code example and explanation of how to read from file in java.


Class Libraries
To aid programmer productivity, the Java Standard Edition (JSE) includes several predefined class packages (aka Java class libraries). Packages/libraries discussed in this set of tutorials are: applets java.applet, language extensions java.lang, utilities java.util, precision math java.math, formatters java.text, file streams java.io, GUIs java.awt and javax.swing, network services java.net, new io (ie. memory mapped) java.nio and remote method invocation java.rmi. Other libraries include beans java.beans, communication ports java.comm, database management java.sql and security java.security. The import reserved word is used to access classes from the libraries (except for java.lang). Unless another library is indicated the following classes are contained in the java.lang package.


How to check permissions on File and Directory
In this article we will learn how to check whether file is read only , whether file has write permission or not etc. In Java we know we have file object to deal with Files if we have created any file in our application using the file object , we have the privilege to check the access permission of that file using simple method of File class in Java.


Creating Java Servlets With NetBeans
Learn to create Java servlets in the NetBeans IDE. The tutorial creates a basic mailing list and explores file access along with some DOM XML. Also covered is deploying the servlets with Glassfish.


MySQL and Java DB
So, finally, more on Java DB-- It’s the Sun-supported version of Apache Derby with all development done with the Apache Derby community. It’s a complete relational database engine, written in 100% Java with a small footprint of 2MB of a JAR file. It runs on Java EE, and Java SE and more. It has a multi-tiered design for different use cases.


How to use Memory Mapped File
Memory Mapped File in Java are special files which allows java program to read and write directly to memory which is extremely fast compare to stream based IO and allows programmer to code high performance java application.


Introduction – java.lang package
A package is a collection of predefined classes and interfaces, generally, having some common functionality (purpose). A package of Java is equivalent to a header file of C/C++. All the packages put together, that comes with JDK software, are known as Java API. The most important package of Java API is java.lang because without it no Java program with some functionality cannot be developed; it may be an application or applet. As this package is inevitable for each and every Java program you write, the package is implicitly imported if the programmer does not import himself; this automatic importing facility exist only for java.lang package and not for other packages.


Building XML With Java And DOM
This tutorial covers building basic XML structures in Java. Learn basic XML structure, and how to build XML in Java with DOM. Also learn to use the TransformerFactory to convert the DOM to strings.


Java beginners course
1: Basic Java
2: Procedural Java
3: Introduction to Objects
4: More Objects
5: Introducing Applets
6: Components
7: Events
8: LayoutManagers, Windows, and Dialogs
9: Images and Menus
10: I/O and Streams
11: Threads
12: Network Programming
13: Cut and Paste, Printing, Future Directions


Java 8: Currying vs Closures
There are many false ideas around about Java 8. Among these is the idea that Java 8 brings closures to Java. This is wrong. Closures have existed in Java since the beginning. But closures are evil. And while Java 8 seems to go toward functional programming, Java closures should be avoided as much as possible. But Java 8 does not help us very much in this area.


How to change File Permissions
Setting file permission in Java is made convenient by methods provided in Java File class like canRead, CanWrite allows you to set read and write permission on file. you can also change permission by using same code.