String a = String
int i = Integer
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(”filename”
out
} catch (IOException e) {
// error processing code
} finally {
if (out != null) {
out
}
}
String methodName = Thread
java
或者是
SimpleDateFormat format = new SimpleDateFormat( "dd
Date date = format
public class OracleJdbcTest
{
String driverClass = "oracle
Connection con;
public void init(FileInputStream fs) throws ClassNotFoundException
{
Properties props = new Properties();
props
String url = props
String userName = props
String password = props
Class
con=DriverManager
}
public void fetch() throws SQLException
{
PreparedStatement ps = con
ResultSet rs = ps
while (rs
{
// do the thing you do
}
rs
ps
}
public static void main(String[] args)
{
OracleJdbcTest test = new OracleJdbcTest();
test
test
}
}
java
java
public static void fileCopy( File in
throws IOException
{
FileChannel inChannel = new FileInputStream( in )
FileChannel outChannel = new FileOutputStream( out )
try
{
// inChannel
// magic number for Windows
int maxCount = (
long size = inChannel
long position =
while ( position < size )
{
position += inChannel
}
}
finally
{
if ( inChannel != null )
{
inChannel
}
if ( outChannel != null )
{
outChannel
}
}
}
private void createThumbnail(String filename
throws InterruptedException
{
// load image from filename
Image image = Toolkit
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker
mediaTracker
// use this to test for errors at this point: System
// determine thumbnail size from WIDTH and HEIGHT
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = image
int imageHeight = image
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio) {
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
}
// draw original image to thumbnail image object and
// scale it to the new size on
BufferedImage thumbImage = new BufferedImage(thumbWidth
Graphics
graphics
graphics
// save thumbnail image to outFilename
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFilename));
JPEGImageEncoder encoder = JPEGCodec
JPEGEncodeParam param = encoder
quality = Math
param
encoder
encoder
out
}
import org
JSONObject json = new JSONObject();
json
json
String output = json
import java
import java
import java
import java
import com
import com
import com
public class GeneratePDF {
public static void main(String[] args) {
try {
OutputStream file = new FileOutputStream(new File("C:Test
Document document = new Document();
PdfWriter
document
document
document
document
file
} catch (Exception e) {
e
}
}
}
System
System
System
System
public class SimpleSingleton {
private static SimpleSingleton singleInstance = new SimpleSingleton();
//Marking default constructor private
//to avoid direct instantiation
private SimpleSingleton() {
}
//Get instance for class SimpleSingleton
public static SimpleSingleton getInstance() {
return singleInstance;
}
}
另一種實現
public enum SimpleSingleton {
INSTANCE;
public void doSomething() {
}
}
//Call the method from Singleton:
SimpleSingleton
import java
import java
import java
import java
import java
import javax
import java
public void captureScreen(String fileName) throws Exception {
Dimension screenSize = Toolkit
Rectangle screenRectangle = new Rectangle(screenSize);
Robot robot = new Robot();
BufferedImage image = robot
ImageIO
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20395.html