小弟刚学java,以前是学过一点delphi,现在学的java有些头痛
请教大家给三个例子,小弟学习一下:
1.java文件拷贝的例子.我在网上找到过,但是没有main函数,命令提示符下通不过.2.java编写的浏览器只要能敲入一个合法的url就能读出网页内容.3.用java实现数据库操作(增,删,改,查),我想先用简单一点的数据库
,就用access吧.以上例子我在网上找到过,但是没有main函数,命令提示符下通不过,我又不知道怎么改.(我刚学只会用 javac命令,今天才在看jcreator)那位大人有这方面源程序,麻烦发给小弟啊,小弟感激不尽啊小弟.cn
请教大家给三个例子,小弟学习一下:
1.java文件拷贝的例子.我在网上找到过,但是没有main函数,命令提示符下通不过.2.java编写的浏览器只要能敲入一个合法的url就能读出网页内容.3.用java实现数据库操作(增,删,改,查),我想先用简单一点的数据库
,就用access吧.以上例子我在网上找到过,但是没有main函数,命令提示符下通不过,我又不知道怎么改.(我刚学只会用 javac命令,今天才在看jcreator)那位大人有这方面源程序,麻烦发给小弟啊,小弟感激不尽啊小弟.cn
import java.io.*;public class CopyTest
{
public static void copy(File src, File dest)
{
FileInputStream fis = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
File fpp = new File(dest.getParent());
try
{
if( !fpp.exists() )
fpp.mkdirs();
if( !dest.exists())
dest.createNewFile();
if( src.isFile() && src.exists() )
{
fis = new FileInputStream(src);
bis = new BufferedInputStream(fis, 4096*2);
fos = new FileOutputStream(dest);
bos = new BufferedOutputStream(fos, 4096*2);
int readBytes = 0;
byte[] buff = new byte[4096];
while( (readBytes = bis.read(buff)) != -1)
{
bos.write(buff);
}
System.out.println("复制结束...");
}
else
{
System.out.println("复制源必须是文件且存在...");
}
} catch (Exception e)
{
e.printStackTrace();
dest.delete();
fpp.delete();
}
finally
{
try
{
bis.close();
bos.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
public static void main(String[] args)
{
File fs = new File("c:/a.mp3");
File fd = new File("c:/xix/复件a.mp3");
CopyTest.copy(fs, fd);
}
}
不过 File fs = new File("c:/a.mp3");
File fd = new File("c:/xix/复件a.mp3")
只能实现c:/a.mp3往c:/xix/复件a.mp3拷贝
好像是绝对路径
有没有办法改成绝对路径?谢谢啊
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class TestClassForNameApp { public static void main(String args[]) { try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out
.println("Oops! Can't find class oracle.jdbc.driver.OracleDriver");
System.exit(1);
} Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger"); stmt = conn.createStatement();
rset = stmt
.executeQuery("select 'Hello '||USER||'!' result from dual");
while (rset.next())
System.out.println(rset.getString(1));
rset.close();
rset = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
} catch (SQLException e) {
System.out.println("Darn! A SQL error: " + e.getMessage());
} finally {
if (rset != null)
try {
rset.close();
} catch (SQLException ignore) {
}
if (stmt != null)
try {
stmt.close();
} catch (SQLException ignore) {
}
if (conn != null)
try {
conn.close();
} catch (SQLException ignore) {
}
}
}
}
access用不了这么复杂啊
谢谢楼上的
继续等
import java.awt.event.*;
import java.net.*;
import java.io.*;import javax.swing.*;
import javax.swing.event.*;public class ReadServerFile extends JFrame {
private JTextField enterField;
private JEditorPane contentsArea;
public ReadServerFile()
{
super( "Simple web browser" );
enterField = new JTextField();
Container container = getContentPane();
enterField.addActionListener(new ForActionListener());
container.add(enterField,BorderLayout.NORTH);
contentsArea = new JEditorPane();
contentsArea.setEditable(false);
contentsArea.addHyperlinkListener(new ForHyperlinkListener());
container.add(contentsArea,BorderLayout.CENTER);
setSize(400,300);
setVisible(true);
}
public void getThePage(String location)
{
try{
contentsArea.setPage( location );
enterField.setText( location );
}catch(IOException e){
JOptionPane.showMessageDialog( this,"error","bad url",JOptionPane.ERROR_MESSAGE );
}
}
public static void main(String args[])
{
ReadServerFile app = new ReadServerFile();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class ForActionListener implements ActionListener{
public void actionPerformed(ActionEvent e1)
{
getThePage(e1.getActionCommand());
}
}
private class ForHyperlinkListener implements HyperlinkListener{
public void hyperlinkUpdate(HyperlinkEvent e2)
{
if(e2.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
getThePage(e2.getURL().toString());
}
}
}