writing objects into file
|
|
|
Question / Problem
|
How to write serialized objects(single,multiple dimensions) into file ?
|
Solution
|
import java.io.*; /** *Class used to store objects into file *This is a sample program to store String array into file * like this we can store any thing which are serialized object * Non-serialize objects (like status of checkbox) are not able to store */ public class WriteObjToFile{ public static void main(String argv[]){ /** String path for linux user for windows use C:\filePath*/ String strPath = "/home/username/desktop/"; String strFileName = "somename.info"; String []strArrNames = {"Sachin","Deepak","Sandeep"}; System.out.println("Data writing has start"); File f = new File(strPath+strFileName); FileOutputStream fileop = new FileOutputStream(f); fileop.writeObject(strArrNames); fileop.close();//Dont forget to close the file fileop.flush();//dont forget to flush System.out.println("The data has been written"); } }
|
Applies to |
|
Core Java
|
Rank It |
|