Tuesday, July 23, 2013
1
| Path path = FileSystems.getDefault().getPath(".", name); |
Want to read all of the bytes in that file? No more looping, here it is:
1
| byte[] filearray = Files.readAllBytes(path); |
Would you rather deal with the file line-by-line? No problem:
1
| List |
Is it a large file that you'd rather use buffered IO with? Here you go:
1
2
3
4
| BufferedReader reader = Files.newBufferedReader(path, Charset.defaultCharset() );String line = null;while ( (line = reader.readLine()) != null ) { /* … */ } |
Surely, it must take more than that to create and write to file, right? Wrong:
1
2
3
| String content = …Files.write( path, content.getBytes(), StandardOpenOption.CREATE); // create new, overwrite if exists |
You can buffer the output and write all of the bytes with one extra line of code:
1
2
3
4
| BufferedWriter writer = Files.newBufferedWriter( path, Charset.defaultCharset(), StandardOpenOption.CREATE);writer.write(content, 0, content.length()); |
Sunday, June 23, 2013
MVN GWT Project
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.5.0 -DgroupId=com.kiahu -DartifactId=basic-project -Dversion=0.0.1-SNAPSHOT -Dpackage=com.kiahu.sample
Sunday, June 9, 2013
Easy Steps to to Switch to Sun Oracls' JDK
I use Linux Mint 15
1) Download JDK1.7, and install it into any directory of your choice, mine was /home/byorn/Programs/jdk1.7
2) Set Java Home
sudo vim /home/byorn/.bash_profile
export JAVA_HOME=/home/byorn/Programs/jdk1.7.0_21
export PATH=$PATH:$JAVA_HOME/bin
3) sudo update-alternatives --install "/usr/bin/java" "java" "/home/byorn/Programs/jdk1.7.0_21/bin/java" 1
4) sudo update-alternatives --config java
1) Download JDK1.7, and install it into any directory of your choice, mine was /home/byorn/Programs/jdk1.7
2) Set Java Home
sudo vim /home/byorn/.bash_profile
export JAVA_HOME=/home/byorn/Programs/jdk1.7.0_21
export PATH=$PATH:$JAVA_HOME/bin
3) sudo update-alternatives --install "/usr/bin/java" "java" "/home/byorn/Programs/jdk1.7.0_21/bin/java" 1
4) sudo update-alternatives --config java
and select your option.
To Test type: java -version
Sunday, February 24, 2013
RSYNC
#!/bin/bashsudo rsync -rltDvu --modify-window=1 --progress --delete --delete-excluded --exclude-from=/home/bob/Bash/BackupBigExclude.txt /home/bob/ /media/harddrive/backup
Explanation of commands:
rsync: this is the program used to sync the data. Rsync basically can check the destination data and see if any changes have been made in the source data so that ONLY the source data that has been changed is updated. VERY useful.
-r: copies directories recursively
-l: copies symlinks as symlinks
-t: preserves modification times
-D: preserves device and special files
-v: shows output (verbose)
-u: skips files that are newer at the destination
--modify-window=1: this is essential if you are backing up to a filesystem that is NOT ext3 or ext2, e.g. NTFS or FAT32. Basically in windows filesystem times are kept as even numbers. This command tells rsync to ignore file changes that are only 1 second in difference from the original. It is almost impossible that you will create a file, sync it, and in ONE second make a change and want to sync it again. So it is safe to use this option and it means that rsync will not back up everything every time simply because of a one second change.
--progress: simply shows the progress
--delete: this is important. Basically rsync syncs files that have been changed. But what if you delete a file from the source directory? This command deletes it from your backed up hard drive as well.
--delete-excluded: this deletes folder/files that you have specifically excluded.
--exclude-from=/home/bob/Bash/BackupExclude.txt: this is the other crucial command. This basically tells rsync to exclude the files/folders found in the list BackupExlude.txt. To create this list do the following:
gedit /home/bob/Bash/BackupExclude.txt
Now in the text editor it is entirely up to you what you want to exlcude.
This is my list:
MyDownloads.VirtualBoxlost+found
Thursday, November 22, 2012
Starting Postgress SQL
Install It
apt-get install postgresql-9.1
Create a user
sudo -u postgres createuser -d -R -P
Give a password for the user.
sudo -su postgres
postgres$ psql -U postgres
ALTER USER postgres with password 'secure-password';
now you can directly connect from Super User like this
psql -U postgres -h localhost
Create a database
createdb mydb
Export from one db to another
pg_dump -C -h localhost -U localuser dbname | psql -h remotehost -U remoteuser
Take a dump
pg_dump -c -U postgres ${fromDataBase} -f ABIMS9JAN13tabledump.sql -h ${fromHost}
Execute the dump
psql -d ${toDataBase} -f dumpfilename.sql -h ${toHost} -U postgres -w password
Install GUI
sudo apt-get install pgadmin3
pgadmin3
pg_dump --username "postgres" -Fc origin > origin.dump
pg_restore --username "postgres" -d target origin.dump
Subscribe to:
Posts (Atom)