My Java Page

Go to My Home PageAbout meDownloadsC ProgrammingVB ProgrammingMy PhotosCool LinksTips & Tricks


                                                              Hello ! Java  Programmers . I  am  a  baby  still in   Java  Programming . And  these  codes below  is  for  beginners . I  am  very  sorry  if  you  came  for  big  thing . But  some  codes  can  be  use  for  you  sometimes . So, have  a  look .
 

//To Create a Directory
import java.io.File;
import java.io.IOException;
class samp
{
Public static void main(String argv[]) throws IOException
{
File mkd=new File(argv[0]);
mkd.mkdir();
}
}

//To Delete a File or Directory
import java.io.File;
import java.io.IOException;
class samp
{
Public static void main(String argv[]) throws IOException
{
File mkd=new File(argv[0]);
mkd.delete();
}
}

//To Rename a File or Directory
import java.io.File;
import java.io.IOException;
class samp
{
Public static void main(String argv[]) throws IOException
{
File old=new File(argv[0]);
File knew=new File(argv[1]);
old.renameTo(knew);
}
}
 

//To Read a File
import java.io.FileInputStream;
import java.io.IOException;
class samp
{
Public static void main(String argv[]) throws IOException
{
long len;
FileInputStream ins=new FileInputStream(argv[0]);
len=ins.available();
while(len>=1)
{
char ch=(char)ins.read();
System.out.print(ch);
len--;
}
ins.close();
}
}
 

//To copy one file to another file( Can also copy Binary files )
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
class samp
{
Public static void main(String argv[]) throws IOException
{
long len;
FileInputStream ins=new FileInputStream(argv[0]);
FileOutputStream ins=new FileOutputStream(argv[1]);
len=ins.available();
while(len>=1)
{
char ch=(char)ins.read();
outs.write(ch);
len--;
}
outs.close();
ins.close();
}
}

//Executing a file during runtime
import java.lang.System;
import java.lang.Runtime;
import java.io.IOException;
class samp
{
Public static void main(String args[]) throws IOException
{
Runtime r=Runtime.getRuntime();
r.exec("C:\\windows\\explorer.exe");
}
}
 


Mail me at:  [email protected] or  [email protected]