Java file I/O

Java provides a number of classes and methods that allow to read and write files. In Java all files are byte-oriented. Two of the most often-used stream classes are FileInputStream and FileOutputStream, which create byte streams linked to files.

  1. To open a file, simple create an object of one of the classes specifying the name of the file as an argument to the constructor.
  2. Use close() to close the file

Syntax

Setting script src dynamically

Suppose you need to call some JavaScript code on your page such as:

  <script src"somecode.js"></script>

However, the somecode.js is different based on other parameters on your page. So you would need to pass a variable rather than the static string to the src. If you just replace somecode.js, with a variable name, you code will not be called.

The following example shows how you can manipulate DOM to define src so that your code runs.

Print screen on Mac

The Mac OS keyboard does not have a print screen button. So this is how to capture your screen on Mac:

  • Hold down Apple key ? + Shift + 3 and release all

The screen shot would appear on your desktop.

You can also do a screen capture for a portion of your screen.

  • Hold down Apple key ? + Shift + 4 and release all key
  • Mouse cursor would change to +
  • Select the region you wish to capture

Easy.

Quick way to find which log file is logging errors

On development systems it is common practice to have different log file to log PHP error logs for different tools and different versions of the same tool. Generally it is a good idea to use meaningful names to make it easy to distinguish between the log files. If you have doubts, you can either look inside the code to see which error log file is being called or do the following:

$ cd ~
$ ls -al /var/log/httpd before.diff

Run the tool such that it would write something to the log file. Then

Setting up multiple displays on Mac OS

It is now common for users to work with multiple monitors. Laptop users, especially, prefer to work on their laptop screen and an external monitor when at they at work or at home. If you are using netflix or some other service to download movies, you would prefer to watch it on large screen rather than your laptop screen, so you would want to connect your computer to a TV or projector.

It is very easy to connect Mac OS computers to external monitors.

Some quick APT commands

Advanced Packaging Tool (APT) is used by Debian system to manage package installations. Following are some quick commands:

Some common commands that can be used with APT:

Installing packages

$ sudo apt-get install package

Removing packages

$ sudo apt-get remove package

Getting a list of packages

$ sudo apt-get update

Upgrading packages

$ sudo apt-get upgrade

Should I choose Apache with or without SSL?

When downloading Apache from apache.org for Microsoft Windows Operating System, you are given two options:

  1. Win32 Binary without crypto (no mod_ssl) (MSI Installer)
  2. Win32 Binary including OpenSSL 0.x (MSI Installer)

OpenSSL is an open-source implementation of SSL and TLS protocols. mod_ssl is a package that provides cryptography for Apache via SSL and TLS. SSL and TLS specify how to securely encrypt and send confidential information over HTTP.

Pages