Monday, May 7, 2012

Java code snap - Create a File

package com.example.javaIO


public class CreateFile
public static void main( String args[] )
try {

File file = new File("/home/user/readme_IO.txt");

if (file.createNewFile()){
    System.out.println("JAVA IO - Created a File - /home/user/readme_IO.txt");
    System.out.println("JAVA IO - Created a File faild - /home/user/readme_IO.txt");

} catch (IOException e) {
System.out.println("JAVA IO - Catch Exception");

Simple program java program to create a file on server.

This example creates a file which is called readme_IO.txt file on server location("/home/user/readme_IO.txt"). It use createNewFile method to create a file, it return true if the file is created otherwise returns false.


No comments:

Post a Comment