This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String a = String.valueOf(2); //integer to numeric string | |
| int i = Integer.parseInt(a); //numeric string to an int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| BufferedWriter out = null; | |
| try { | |
| out = new BufferedWriter(new FileWriter(”filename”, true)); | |
| out.write(”aString”); | |
| } catch (IOException e) { | |
| // error processing code | |
| } finally { | |
| if (out != null) { | |
| out.close(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| java.util.Date = java.text.DateFormat.getDateInstance().parse(date String); | |
| //or | |
| SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" ); | |
| Date date = format.parse( myString ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OracleJdbcTest | |
| { | |
| String driverClass = "oracle.jdbc.driver.OracleDriver"; | |
| Connection con; | |
| public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException | |
| { | |
| Properties props = new Properties(); | |
| props.load(fs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| java.util.Date utilDate = new java.util.Date(); | |
| java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void fileCopy( File in, File out ) | |
| throws IOException | |
| { | |
| FileChannel inChannel = new FileInputStream( in ).getChannel(); | |
| FileChannel outChannel = new FileOutputStream( out ).getChannel(); | |
| try | |
| { | |
| // magic number for Windows, 64Mb - 32Kb) | |
| int maxCount = (64 * 1024 * 1024) - (32 * 1024); | |
| long size = inChannel.size(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void createThumbnail(String filename, int thumbWidth, int thumbHeight, int quality, String outFilename) | |
| throws InterruptedException, FileNotFoundException, IOException | |
| { | |
| // load image from filename | |
| Image image = Toolkit.getDefaultToolkit().getImage(filename); | |
| MediaTracker mediaTracker = new MediaTracker(new Container()); | |
| mediaTracker.addImage(image, 0); | |
| mediaTracker.waitForID(0); | |
| // use this to test for errors at this point: System.out.println(mediaTracker.isErrorAny()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://viralpatel.net/blogs/2009/02/creating-parsing-json-data-with-java-servlet-struts-jsp-json.html | |
| //http://viralpatel.net/blogs/download/json/json-rpc-1.0.jar | |
| import org.json.JSONObject; | |
| ... | |
| ... | |
| JSONObject json = new JSONObject(); | |
| json.put("city", "Mumbai"); | |
| json.put("country", "India"); | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://viralpatel.net/blogs/2009/04/generate-pdf-file-in-java-using-itext-jar.html | |
| import java.io.File; | |
| import java.io.FileOutputStream; | |
| import java.io.OutputStream; | |
| import java.util.Date; | |
| import com.lowagie.text.Document; | |
| import com.lowagie.text.Paragraph; | |
| import com.lowagie.text.pdf.PdfWriter; |
OlderNewer