On Windows
https://access.redhat.com/solutions/19170
On Linux
https://access.redhat.com/solutions/18178
https://access.redhat.com/solutions/19170
On Linux
https://access.redhat.com/solutions/18178
C:\Users\sonal_chaudhary>cd C:\Oracle\Oracle_ECM1\oui\bin\
C:\Oracle\Oracle_ECM1\oui\bin>setup.exe -deinstall -ignoreSysPrereqs -jreLoc C:\Java\jre7
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Main {
private static final String SOURCE_FILE = "D:\\test.jar";
public static void main(String[] args) {
Main io = new Main();
try {
long startTime = System.currentTimeMillis();
io.readWrite(SOURCE_FILE, "D:\\test1.jar");
long endTime = System.currentTimeMillis();
System.out.println("Time taken for reading and writing using default behaviour : " + (endTime - startTime) +
" milli seconds");
long startTime1 = System.currentTimeMillis();
io.readWriteBuffer(SOURCE_FILE, "D:\\test2.jar");
long endTime1 = System.currentTimeMillis();
System.out.println("Time taken for reading and writing using buffered streams : " +
(endTime1 - startTime1) + " milli seconds");
long startTime2 = System.currentTimeMillis();
io.readWriteArray(SOURCE_FILE, "D:\\test3.jar");
long endTime2 = System.currentTimeMillis();
System.out.println("Time taken for reading and writing using custom buffering : " +
(endTime2 - startTime2) + " milli seconds");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void readWrite(String fileFrom, String fileTo) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(fileFrom);
out = new FileOutputStream(fileTo);
while (true) {
int bytedata = in.read();
if (bytedata == -1)
break;
out.write(bytedata);
}
} finally {
if (in != null)
in.close();
if (out != null)
out.close();
}
}
public static void readWriteBuffer(String fileFrom, String fileTo) throws IOException {
InputStream inBuffer = null;
OutputStream outBuffer = null;
try {
InputStream in = new FileInputStream(fileFrom);
inBuffer = new BufferedInputStream(in);
OutputStream out = new FileOutputStream(fileTo);
outBuffer = new BufferedOutputStream(out);
while (true) {
int bytedata = inBuffer.read();
if (bytedata == -1)
break;
out.write(bytedata);
}
} finally {
if (inBuffer != null)
inBuffer.close();
if (outBuffer != null)
outBuffer.close();
}
}
public static void readWriteArray(String fileFrom, String fileTo) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(fileFrom);
out = new FileOutputStream(fileTo);
int availableLength = in.available();
byte[] totalBytes = new byte[availableLength];
int bytedata = in.read(totalBytes);
out.write(totalBytes);
} finally {
if (in != null)
in.close();
if (out != null)
out.close();
}
}
}
OUTPUT
Time taken for reading and writing using default behaviour : 5188 milli seconds
Time taken for reading and writing using buffered streams : 3105 milli seconds
Time taken for reading and writing using custom buffering : 7 milli seconds
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
public class PropertiesTest {
public static void main(String[] args) {
Properties table = new Properties();
// set properties
table.setProperty("color", "blue");
table.setProperty("width", "200");
System.out.println("After setting properties");
listProperties(table);
// replace property value
table.setProperty("color", "red");
System.out.println("After replacing properties");
listProperties(table);
saveProperties(table);
table.clear(); // empty table
System.out.println("After clearing properties");
listProperties(table);
loadProperties(table);
// get value of property color
Object value = table.getProperty("color");
// check if value is in table
if (value != null)
System.out.printf("Property color's value is %s%n", value);
else
System.out.println("Property color is not in table");
}
// save properties to a file
private static void saveProperties(Properties props) {
// save contents of table
try {
FileOutputStream output = new FileOutputStream("props.dat");
props.store(output, "Sample Properties"); // save properties
output.close();
System.out.println("After saving properties");
listProperties(props);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
// load properties from a file
private static void loadProperties(Properties props) {
// load contents of table
try {
FileInputStream input = new FileInputStream("props.dat");
props.load(input); // load properties
input.close();
System.out.println("After loading properties");
listProperties(props);
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
// output property values
private static void listProperties(Properties props) {
Set<object> keys = props.keySet(); // get property names
// output name/value pairs
for (Object key : keys)
System.out.printf("%s\t%s%n", key, props.getProperty((String)key));
System.out.println();
}
}
OUTPUT
After setting properties
color blue
width 200
After replacing properties
color red
width 200
After saving properties
color red
width 200
After clearing properties
After loading properties
color red
width 200
Property color's value is red
src.dir=src
classes.dir=classes
main-class=com.mypkg.PortfolioManager
lib.dir=lib
docs.dir=docs
projectName=AntTutorial
<?xml version="1.0" encoding="windows-1252" ?>
<!--Ant buildfile generated by Oracle JDeveloper-->
<!--Generated Apr 20, 2015 4:09:46 PM-->
<project xmlns="antlib:org.apache.tools.ant" name="Project" default="all" basedir=".">
<property file="build.properties"/>
<target name="clean">
<delete dir="${classes.dir}"/>
<delete dir="${docs.dir}"/>
</target>
<target name="init">
<mkdir dir="${classes.dir}"/>
<!--<mkdir dir="${docs.dir}"/>-->
</target>
<path id="classpath">
<fileset dir="${lib.dir}" includes="**/*.jar"/>
</path>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
</target>
<!--<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>-->
<target name="jar" depends="compile">
<jar destfile="${projectName}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="main" depends="clean,compile,jar"/>
</project>