February 27, 2013

Delete File in java

How to delete a file in java



package blackberry;

import java.io.*;
 
public class DeleteFile

{
 
private static void deletefile(String file)
{
 
File f1 = new File(file);

boolean success = f1.delete();

if (!success)
{
 
System.out.println("Deletion failed.");

System.exit(0);
}

else
{
System.out.println("File deleted Successfully.");
}

}
 
public static void main(String[] ran)

{
 
    switch(args.length)
{
 
case 0: System.out.println("File has not mentioned.");
 
          System.exit(0);
 
case 1: deletefile(ran[0]);

         System.exit(0);
 
default : System.out.println("Multiple files are not allow.");
 
            System.exit(0);
  
 }
 
}

}

.ini file


Gutmann algorithm for secure file deletion read here

java blog

Event Listener example in java frame


Event Handling Interface in java with Examples


EventListener : A Listener is called when user invoke an event either through a user interface or through code. Listener are supported by java swing. There are container listener, caret listener, key event listener, window listener in java. You can implements multiple listener event to same class in java.


 import java.awt.*;
import java.awt.event.*;

public class Technology extends Frame implements WindowListener,ActionListener {
    TextField text = new TextField(20);
    Button b;
    private int numClicks = 0;

    public static void main(String[] args) {
        Technology myWindow = new Technology ("Duck Dynasty");
        myWindow.setSize(350,100);
        myWindow.setVisible(true);
    }

    public Technology(String title) {

        super(title);
        setLayout(new FlowLayout());
        addWindowListener(this);
        b = new Button("Click me");
        add(b);
        add(text);
        b.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        numClicks++;
        text.setText("Button Clicked " + numClicks + " times");
    }

    public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }

    public void windowOpened(WindowEvent e) {}
    public void windowActivated(WindowEvent e) {}
    public void windowIconified(WindowEvent e) {}
    public void windowDeiconified(WindowEvent e) {}
    public void windowDeactivated(WindowEvent e) {}
    public void windowClosed(WindowEvent e) {}

}



February 04, 2013

Java simple Date format example



How to parse date in simple date format


package

BlackBery;

import

java.text.SimpleDateFormat;

import

java.util.Date;

/**
* formatting a date in java examples
*/


/**
*

@author BlackBerry

*
*/
public

class ParsingDate {
/**

*

@param args 2010-11-12

*/

public static void main(String[] args) {
// TODO Todays days formating

SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(" Date for blackberry application : "+s.format(new Date()));
}
}




Facebook comments