You can use class in package java.io.* to manage file with java
for example below
Example code for read file line by line with Java
FileInputStream fs = new FileInputStream("filename.txt");
DataInputStream ds = new DataInputStream(fs);
BufferedReader br = new BufferedReader(new InputStreamReader(ds));
String tmp;
while ((tmp = br.readLine()) != null) {
System.out.println (tmp);
}
ds.close();
Example code for Write file with java FileWriter fw = new FileWriter("file_name.txt");
BufferedWriter out = new BufferedWriter(fw);
out.write("Test Wrrite1");
out.write("Test Wrrite2");
out.write("Test Wrrite3");
out.close();
Class is the blueprint to create Object Class is learning the basics of OOP that everyone must know.
for example
Object of Class Car is My car .
Class structure
prefix eg.(public,protected) class ClassName { }
public class MyClass{
//implement some things
}
Today I will present how to Format Date with java.text.* package
Class
java.text.SimpleDateFormat for example below
Date date=new Date();
System.out.println("No format :"+date);
java.text.SimpleDateFormat df= new java.text.SimpleDateFormat();
System.out.println("No pattern format :"+df.format(date));
df.applyPattern("dd/mm/yyyy");
System.out.println("dd/mm/yyyy format :"+df.format(date));
df.applyPattern("dd/mm/yyyy HH:mm:ss");
System.out.println("dd/mm/yyyy HH:mm:ss format :"+df.format(date));
Output for Java SimpleDateFormat
No format :Thu Apr 05 16:29:18 ICT 2012No pattern format :5/4/2555, 16:29 น.dd/mm/yyyy format :05/29/2555dd/mm/yyyy HH:mm:ss format :05/29/2555 16:29:18