1. 把Strings转换成int和把int转换成String
String a = String.valueOf(2);
//integer to numeric string int i = Integer.parseInt(a); //numeric
string to an int String a = String.valueOf(2);
//integer to numeric stringint i = Integer.parseInt(a); //numeric string to an
int
2. 向javajavajavajavajdbcoracleoraclejdbcoraclejdbcoracleoraclejdbcoraclejdbcoraclejdbcoraclejdbcoracleoraclejdbcoraclejdbcjavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajava文件中添加文本 Updated: Thanks Simone for pointing to exception. I have changed the code. BufferedWriter ut = null; try { out = new BufferedWriter(new FileWriter(”filename”, true)); out.write(”aString”); } catch (IOException e) { // error processing code } finally { if (out != null) { out.close(); } } BufferedWriter ut = null;try {out = new BufferedWriter(new FileWriter(”filename”, true));out.write(”aString”);} catch (IOException e) {// error processing code} finally {if (out != null) {out.close();}} 3. 获取现在正调用的方法名 String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName(); String methodName = Thread.currentThread().getStackTrace()[1].getMethodName
();
4. 在中将String型转换成Date型javajavajavajava.util.Date =
.text.DateFormat.getDateInstance().parse(date String); .util.Date = .text.DateFormat.getDateInstance().parse(date
String);or SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy"
); Date date = format.parse( myString ); SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );Date date
= format.parse( myString );
5. 通过 链接数据库 public class Test { String driverClass = "..driver.Driver"; Connection con; public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException { Properties props = new Properties(); props.load(fs); String url = props.getProperty("db.url"); String userName = props.getProperty("db.user"); String password = props.getProperty("db.password"); Class.forName(driverClass); con=DriverManager.getConnection(url, userName, password); } public void fetch() throws SQLException, IOException { PreparedStatement ps = con.prepareStatement("select SYSDATE from dual"); ResultSet rs = ps.executeQuery(); while (rs.next()) { // do the thing you do } rs.close(); ps.close(); } public static void main(String[] args) { Test test = new Test(); test.init(); test.fetch(); } } public class Test{String driverClass = "..driver.Driver";Connection con;public void init(FileInputStream fs) throws ClassNotFoundException,SQLException, FileNotFoundException, IOException{Properties props = new Properties();props.load(fs);String url = props.getProperty("db.url");String userName = props.getProperty("db.user");String password = props.getProperty("db.password");Class.forName(driverClass);con=DriverManager.getConnection(url, userName, password);}public void fetch() throws SQLException, IOException{PreparedStatement ps = con.prepareStatement("select SYSDATE fromdual");ResultSet rs = ps.executeQuery();while (rs.next()){// do the thing you do}rs.close();ps.close();}public static void main(String[] args){Test test = new Test();test.init();test.fetch();}} 6.将中的util.Date转换成sql.Date这一片段显示如何将一个 util Date转换成sql Date用于数据库javajavajavajavajavajavajavajava.util.Date utilDate = new
.util.Date(); .sql.Date sqlDate = new .sql.Date
(utilDate.getTime()); .util.Date utilDate = new .util.Date();.sql.Date sqlDate =
new .sql.Date(utilDate.getTime());
7. 使用NIO快速复制文件 public static void fileCopy( File in, File out ) throws IOException { FileChannel inChannel = new FileInputStream( in ).getChannel(); FileChannel utChannel = new FileOutputStream( out ).getChannel(); try { // inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows // magic number for Windows, 64Mb - 32Kb) int maxCount = (64 * 1024 * 1024) - (32 * 1024); long size = inChannel.size(); long position = 0; while ( position < size ) { position += inChannel.transferTo( position, maxCount, outChannel ); } } finally { if ( inChannel != null ) { inChannel.close(); } if ( outChannel != null ) { outChannel.close(); } } } public static void fileCopy( File in, File out )throws IOException{FileChannel inChannel = new FileInputStream( in ).getChannel();FileChannel utChannel = new FileOutputStream( out ).getChannel();try{// inChannel.transferTo(0, inChannel.size(), outChannel); // original-- apparently has trouble copying large files on Windows// magic number for Windows, 64Mb - 32Kb)int maxCount = (64 * 1024 * 1024) - (32 * 1024);long size = inChannel.size();long position = 0;while ( position < size ){ position += inChannel.transferTo( position, maxCount, outChannel );}}finally{if ( inChannel != null ){ inChannel.close();}if ( outChannel != null ){ outChannel.close();}}} 8. 帖子内容太多 不让发 大家可以去这里参考吧 http://www.gjrencai.com/newsShow.asp?dataID=684
String a = String.valueOf(2);
//integer to numeric string int i = Integer.parseInt(a); //numeric
string to an int String a = String.valueOf(2);
//integer to numeric stringint i = Integer.parseInt(a); //numeric string to an
int
2. 向javajavajavajavajdbcoracleoraclejdbcoraclejdbcoracleoraclejdbcoraclejdbcoraclejdbcoraclejdbcoracleoraclejdbcoraclejdbcjavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajavajava文件中添加文本 Updated: Thanks Simone for pointing to exception. I have changed the code. BufferedWriter ut = null; try { out = new BufferedWriter(new FileWriter(”filename”, true)); out.write(”aString”); } catch (IOException e) { // error processing code } finally { if (out != null) { out.close(); } } BufferedWriter ut = null;try {out = new BufferedWriter(new FileWriter(”filename”, true));out.write(”aString”);} catch (IOException e) {// error processing code} finally {if (out != null) {out.close();}} 3. 获取现在正调用的方法名 String methodName =
Thread.currentThread().getStackTrace()[1].getMethodName(); String methodName = Thread.currentThread().getStackTrace()[1].getMethodName
();
4. 在中将String型转换成Date型javajavajavajava.util.Date =
.text.DateFormat.getDateInstance().parse(date String); .util.Date = .text.DateFormat.getDateInstance().parse(date
String);or SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy"
); Date date = format.parse( myString ); SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );Date date
= format.parse( myString );
5. 通过 链接数据库 public class Test { String driverClass = "..driver.Driver"; Connection con; public void init(FileInputStream fs) throws ClassNotFoundException, SQLException, FileNotFoundException, IOException { Properties props = new Properties(); props.load(fs); String url = props.getProperty("db.url"); String userName = props.getProperty("db.user"); String password = props.getProperty("db.password"); Class.forName(driverClass); con=DriverManager.getConnection(url, userName, password); } public void fetch() throws SQLException, IOException { PreparedStatement ps = con.prepareStatement("select SYSDATE from dual"); ResultSet rs = ps.executeQuery(); while (rs.next()) { // do the thing you do } rs.close(); ps.close(); } public static void main(String[] args) { Test test = new Test(); test.init(); test.fetch(); } } public class Test{String driverClass = "..driver.Driver";Connection con;public void init(FileInputStream fs) throws ClassNotFoundException,SQLException, FileNotFoundException, IOException{Properties props = new Properties();props.load(fs);String url = props.getProperty("db.url");String userName = props.getProperty("db.user");String password = props.getProperty("db.password");Class.forName(driverClass);con=DriverManager.getConnection(url, userName, password);}public void fetch() throws SQLException, IOException{PreparedStatement ps = con.prepareStatement("select SYSDATE fromdual");ResultSet rs = ps.executeQuery();while (rs.next()){// do the thing you do}rs.close();ps.close();}public static void main(String[] args){Test test = new Test();test.init();test.fetch();}} 6.将中的util.Date转换成sql.Date这一片段显示如何将一个 util Date转换成sql Date用于数据库javajavajavajavajavajavajavajava.util.Date utilDate = new
.util.Date(); .sql.Date sqlDate = new .sql.Date
(utilDate.getTime()); .util.Date utilDate = new .util.Date();.sql.Date sqlDate =
new .sql.Date(utilDate.getTime());
7. 使用NIO快速复制文件 public static void fileCopy( File in, File out ) throws IOException { FileChannel inChannel = new FileInputStream( in ).getChannel(); FileChannel utChannel = new FileOutputStream( out ).getChannel(); try { // inChannel.transferTo(0, inChannel.size(), outChannel); // original -- apparently has trouble copying large files on Windows // magic number for Windows, 64Mb - 32Kb) int maxCount = (64 * 1024 * 1024) - (32 * 1024); long size = inChannel.size(); long position = 0; while ( position < size ) { position += inChannel.transferTo( position, maxCount, outChannel ); } } finally { if ( inChannel != null ) { inChannel.close(); } if ( outChannel != null ) { outChannel.close(); } } } public static void fileCopy( File in, File out )throws IOException{FileChannel inChannel = new FileInputStream( in ).getChannel();FileChannel utChannel = new FileOutputStream( out ).getChannel();try{// inChannel.transferTo(0, inChannel.size(), outChannel); // original-- apparently has trouble copying large files on Windows// magic number for Windows, 64Mb - 32Kb)int maxCount = (64 * 1024 * 1024) - (32 * 1024);long size = inChannel.size();long position = 0;while ( position < size ){ position += inChannel.transferTo( position, maxCount, outChannel );}}finally{if ( inChannel != null ){ inChannel.close();}if ( outChannel != null ){ outChannel.close();}}} 8. 帖子内容太多 不让发 大家可以去这里参考吧 http://www.gjrencai.com/newsShow.asp?dataID=684
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货