Thursday, August 30, 2012

Java Program to Write Lines of Text to a File + Source Code

To learn the Basics of file manipulation in java ,the best way to start is by writing simple code to write some text to file.The following is a sample program that writes text to file using BufferedWriter Class

It uses the File Class to open the File to the BufferedWriter Class,which writes some sample text to the file.The main class used is the Writer Class intended for writing stream data to files.

Below is the complete source Code to implement a Simple File Writer in Java


 import java.io.*;  
 public class FileWriter {  
  public static void main(String[] args)throws IOException{  
  String towrite = "Hello World";  
  Writer data = null;  
  File file = new File("myfile.txtt");  
  data = new BufferedWriter(new FileWriter(file));  
  data.write(text);  
  data.close();  
  System.out.println("Text Written");   
  }  
 }  

Wednesday, August 8, 2012

How to set the Java Compiler path for direct running from command Line

There is an easy way to set the Java Compiler Path(javac.exe) and Java Interpreter path(java.exe)without typing long lines of command.

The following are steps to set the JDK(Java Development Kit) path easily

1.Click on Start

2.Right Click on Computer>Properties

3.Click on Advanced System Settings

4.Click on Environmental Variables Button




5.Click on New



6.In the variable name field type PATH



7.In the variable value field enter the path in which JDK is installed (usually C:\Program Files\Java\jdk1.7.0_05\bin),include the bin folder.

8.Click on OK

9.Open CMD and type javac.exe or java.exe or the name of any executable,it will be launched.

See the video tutorial for more information



 
    

Which is the Best Photo Watermarking Software

Photo Theft is becoming more and more common in the web with the outburst of social websites like Facebook,Google Plus and Image sharing se...