易截截图软件、单文件、免安装、纯绿色、仅160KB

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详解

 
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......

Java线程同步机制synchronized关键字的理解

【IT168 技术文档】线程同步:
  由于同一进程的多个线程共享同一片存储空间,在带来方便的同时,也带来了访问冲突这个严重的问题。Java语言提供了专门机制以解决这种冲突,有效避免了同一个数据对象被多个线程同时访问。
  需要明确的几个问题:
  1)synchronized关键字可以作为函数的修饰符,也可作为函数内的语 ......

Java泛型应该注意的细节

1、不可以用一个本地类型(如int   float)来替换泛型.比如List<Integer>不能用List<int>型式
2、运行时类型检查,不同类型的泛型类是等价的(Pair<String>与Pair<Employee>是属于同一个
类型 Pair),这一点要特别注意:即如果a instanceof
Pair<String>==true的话,并不代表a. ......

java输入数据的两种方法

1 基本方法
 import java.io.*;
public class input1
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader buf = new BufferedReader(reader);
/* 或者
BufferedReader buf; ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号