Java实现:文件传输
//代码经过编译,运行,证明可以运行
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
import javax.swing.filechooser.FileFilter;
public class Ftp extends JLabel
{
private JButton openButton;
private JButton saveButton;
JFileChooser fc;
String fileName;
int result;
Ftp()
{
setLayout(new GridLayout());
JButton openButton = new JButton("Open");
openButton.addActionListener(new openFile());
JButton saveButton = new JButton("Save");
saveButton.addActionListener(new saveFile());
add(openButton);
add(saveButton);
}
class openFile implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
fc = new JFileChooser();
result = fc.showOpenDialog(Ftp.this);
File file = fc.getSelectedFile();
if(file != null && result == JFileChooser.APPROVE_OPTION)
{
fileName = file.getAbsolutePath();
System.out.println("选择你要打开的文件:" + fileName);
try
{
File file1 = new File(fileName);
FileInputStream fos = new FileInputStream(file1);
ServerSocket ss = new ServerSocket(2048);
Socket client = ss.accept();
OutputStream netOut = client.getOutputStream();
OutputStream doc = new DataOutputStream(new BufferedOutputStream(netOut));
byte[] buf = new byte[2048];
int num = fos.read(buf);
while(num != (-1))
{
&nb
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
类的初始化和对象初始化是 JVM 管理的类型生命周期中非常重要的两个环节,Google 了一遍网络,有关类装载机制的文章倒是不少,然而类初始化和对象初始化的文章并不多,特别是从字节码和 JVM 层次来分析的文章更是鲜有所见。
本文主要对类和对象初始化全过程进行分析,通过一个实际问题引入,将源代码转换成 JVM 字节码后, ......
编程:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。但是要保证汉字不被截半个,如"我ABC"4,应该截为"我AB",输入"我ABC汉DEF",6,应该输出为"我ABC"而不是"我ABC+汉的半个"。
public static String substring(String str, int toCount,String& ......
中国Java培训,尤其是北京的Java所谓高端培训,至少已经火了5年以上了,最近有一些想法和大家分享一下。
现在比较有名的Java培训有 达内,东方标准,尚学堂,传智博客,赛尔凯达,还有蓝点等等吧其他名气不怎么大了,对了还有北大青鸟 。
最早知道的是北大青鸟,上大学就知道这个了 ......