Sunday, April 17, 2011

Understanding Streams in Java

Understanding Streams in Java


By: Mohammed Saudi.

Download examples :

A Data Stream is a flow of data between data source and data sink (the data goes to it).
Data source or sink could be for example disk file, device or network socket.

Two types of streams available in java ; Byte streams and Character streams. They differ in the level they are dealing with data; either data is read/written in 8-bit fashion ( byte stream) or in 16-bit unicode character fashion (character based).

If you are not working with images or sounds, it would be easier and better to use character-based streams; they handle the conversion and encoding stuff.

There is also a helpful classes ( and that handle the gap between those two types. They convert byte data into character-based.

Also there is a Data stream classes that reads data directly by type (int, string, float ,... ). They relay on a stream objects.

DataInputStream and DataOutputStream. are typical examples.
DataOutputStream(OutputStream out)
DataInputStream(InputStream in)

Examples of Byte Stream classes are
InputStreamReader, OutputStreamWriter, BufferedReader and BufferedWriter.

Examples of character Stream classes ( data sink streams) are
FileReader and FileWriter

===== Reading Files using byte-based streams ====

This Program reads "myInputFile.txt" file byte by byte and write the data into the file "myOutputFile.txt"
you should have myInputFile.txt in the same path of this java file

By: Mohammed Saudi.


public class ReadBytes {
public static void main(String[] args) throws IOException {
FileInputStream inStream = null;
FileOutputStream outStream = null;
try {
inStream = new FileInputStream("myInputFile.txt");
outStream = new FileOutputStream("myOutputFile.txt");
int c; //I use int here because I use the read function blow which returns an integer.

while ((c = != -1) {


catch (Exception fe){


finally {
if (inStream != null) {
if (outStream != null) {

===== Reading Files using character-based streams ====

This Program is the same as "ReadBytes" except it uses filereader and filewritter classes
you should have myInputFile.txt in the same path of this java file

* note: you may have a problem in character encoding when using filewritter class.
If so, use the OutputStreamWriter on a FileOutputStream instead.

By: Mohammed Saudi.



// Displays contents of a file
//(e.g. java Type app.ini)
public class ReadChars
public static void main(
String args[]) throws Exception
// Open input/output and setup variables
FileReader fr = new FileReader("myInputFile.txt");
FileWriter fw = new FileWriter("myOutputFile.txt");

char cToReadIn[] = new char[1000];
int read = 0;

// Read (and print) till end of file
while ((read = != -1)

// Close shop

Download examples :

Wednesday, April 13, 2011

fix firefox youtube fullscreen error in ubuntu

Hello All,
There is a problem in firefox when playing youtube videos in full screen mode. Here is the solution :

sudo mkdir /etc/adobe
sudo echo "OverrideGPUValidation = 1" >> /etc/adobe/mms.cfg

That's it.

Friday, April 8, 2011

Install gcc windows

To install gcc compiler in windows operating system do the following :

1- go to to download the mingw installer or simply go directly to

2- click download mingw-get-inst-****
this will download a small exe to help you download and install the required files.
3- click the exe file downloaded and click next

4- keep clicking Next as there is no changes required.

NOTE: You can install the C++ compiler -If you want - by just clicking the check box besides C++ compiler

The installer will do the rest of the job for you. It will download and install the required files.
Then click finish.


You will need to add environment variable to the system to be able to use the gcc command at the command prompt.
Follow the next steps to do this :

1- right click on my computer - > Properties -> Advanced - > Environment variables

2- click the PATH variable as indicated then click EDIT
3- Add " ; C:\MinGW\bin to the end of the line "
semicolon followed by the path

4 - Now you are able to compile your c applications using GCC compiler.

** To do this, Click Start -> RUN (or keyboard windows tbutton +R) and write CMD

Compile your code by writing the following command:

gcc c_file_name_path -o c_output_filename

That's it.

Thursday, April 7, 2011

Installing VMware player ubuntu

Hello All,
VMWare offers a free software called VMWare player which you can use to work with virtual machines. of course It has less features than the Work Station version like the ability to make a team and record your WM session but you still can have your work done with the FREE version.

To install it in ubuntu do the following:

first download the software from HERE,
note: you will need to register to be able to download.
then :
Open terminal
Change to the directory you downloaded your file to
issue the following command ,,,
gksudo bash ./VMware-Player-xxxxxxxx
where xxxx is the version details.
This will run a GUI installer, follow the instruction and after you finish, 
you will find it installed in Applications, System Tools , VMware player

Enjoy !.

Monday, April 4, 2011

Configuring Proxy Settings Manually Ubuntu


sudo gedit /etc/apt/apt.conf &

then inside apt.conf file write your proxy settings in the following format:
for http:
Acquire::http::Proxy "http://proxy_server_here:port_here";

for ftp: example
Acquire::ftp::Proxy "";

If you want to change this, just remove the lines we just wrote.

have fun