Friday, May 30, 2008

Java Library to get Folder Content

FolderContentLib is the java library published under GPL license written by Chandima prabath ariyarathna. Using this library, you can check all file and file path inside the folder include the file which are include in the subfolders .

Features:-

File content(String folderPath)
Using this method you can get file names which are inside the folder.This method return String Array.



PathContent(String folderPath)
Using this method you can get file names and path which are inside the folder.This method return String Array.



How to access:-
Example source code to access library.


If you want to get source code Click on the picture

Download Lib Download Source

Wednesday, May 28, 2008

Open source license

software licensing

Allowing an individual or group to use a piece of software. Nearly all applications are licensed rather than sold. There are a variety of different types of software licenses. Some are based on the number machines on which the licensed program can run whereas others are based on the number of users that can use the program. Most personal computer software licenses allow you to run the program on only one machine and to make copies of the software only for backup purposes. Some licenses also allow you to run the program on different computers as long as you don't use the copies simultaneously

Reference:-webopedia

GNU LESSER GENERAL PUBLIC LICENSE
Copyright (C) 2007 Free Software Foundation, Inc.

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below.


Additional Definitions.

As used herein, “this License” refers to version 3 of the GNU Lesser General Public License, and the “GNU GPL” refers to version 3 of the GNU General Public License.

“The Library” refers to a covered work governed by this License, other than an Application or a Combined Work as defined below.

An “Application” is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library.

A “Combined Work” is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the “Linked Version”.

The “Minimal Corresponding Source” for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version.

The “Corresponding Application Code” for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work.

Referense :-http://www.gnu.org

Thursday, May 22, 2008

Get Local Ip address using java

Its very simple ,for the testing you want to import "java.net.InetAddress" package

//Get an instance of InetAddress for the local computer
InetAddress inetAddress = InetAddress.getLocalHost();

//Get a string representation of the ip address
String ipAddress = inetAddress.getHostAddress();

//Print the ip address
System.out.println(ipAddress);

Friday, May 9, 2008

Java Source code to check patition free space in Linux & Windows

this is java code for check free space in partition..


private static final Pattern NON_DIGIT = Pattern.compile("(([^0-9]*))");
private static final Pattern WORDS = Pattern.compile("(\\s*(\\S+)\\s*)");

public static long getFreeSpace(File file) {
final String osName = System.getProperty("os.name");
try {
if (osName.indexOf("Windows") != -1) {
return freeSpaceWindow(file);
} else if (osName.equals("Linux")) {
return freeSpaceUnix(file);
} else {
System.err.println("Unknown os=" + osName);
return freeSpaceUnix(file);
}
} catch (IOException ex) {
ex.printStackTrace(System.err);
return -1;
}
} // end getFreeSpace

private static long freeSpaceUnix(File file) throws IOException {
Process process = Runtime.getRuntime().exec("df");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
List vectorinfos = new ArrayList(8);
while ((line = reader.readLine()) != null) {
if (line.charAt(0) == '/') {
vectorinfos.add(WORDS.split(line));
} // end if line.startwith("/")
} // end while
for (int i = vectorinfos.size() - 1; i >= 0; i--) {
String[] info = (String[]) vectorinfos.get(i);
if (file.getAbsolutePath().indexOf(info[5]) != -1) {
return Long.parseLong(info[3]);
} // end if
} // end for
return -1;
}

private static long freeSpaceWindow(File file) throws IOException {

Process process = Runtime.getRuntime().exec("cmd /c dir /-c " + file.getAbsolutePath());
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null && !line.endsWith("libres") && !line.endsWith("free")) { }
if (line == null) {
return -1;
}
line = line.substring(line.lastIndexOf(")") + 1);
Matcher matcher = NON_DIGIT.matcher(line);
line = matcher.replaceAll("");
return Long.parseLong(line);
}

Friday, May 2, 2008

How to write Port Scaner using Java

This is source code for port scanner.Very easy to implement.If port is available return true.If port is unavailable return false.



public static boolean PortScanner(String host,int port) throws UnknownHostException
{

Socket worker = null; //makes all the connections
int Port =port; //make port
InetAddress hostAddress; //stores the IP address of the target
boolean status=false;
String Host=host;

hostAddress=InetAddress.getByName(Host);

try
{
worker= new Socket(hostAddress,Port);
status=true;
}
catch(java.io.IOException e)
{
status=false;
}

finally
{
try
{
worker.close();
}
catch(java.io.IOException e){}
catch(NullPointerException e){}
}

return status;
}

 

blogger templates 3 columns | Make Money Online