热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android中Socket大文件断点上传示例

Android中Socket大文件断点上传示例-什么是Socket?     所谓Socket通常也称作“套接字”,用于描述IP地址和端口,是一个通信连的句柄,应用程序通常通过“套

什么是Socket?     

所谓Socket通常也称作“套接字”,用于描述IP地址和端口,是一个通信连的句柄,应用程序通常通过“套接字”向网络发送请求或者应答网络请求,它就是网络通信过程中端点的抽象表示。它主要包括以下两个协议:

TCP (Transmission Control Protocol 传输控制协议):传输控制协议,提供的是面向连接、可靠的字节流服务。当客户和服务器彼此交换数据前,必须先在双方之间建立一个TCP连接,之后才能传输数据。TCP提供超时重发,丢弃重复数据,检验数据,流量控制等功能,保证数据能从一端传到另一端。

UDP (User Datagram Protocl 用户数据报协议):用户数据报协议,是一个简单的面向数据报的运输层协议。UDP不提供可靠性,它只是把应用程序传给IP层的数据报发送出去,但是并不能保证它们能到达目的地。由于UDP在传输数据报前不用在客户和服务器之间建立一个连接,且没有超时重发等机制,故而传输速度很快。

详细解说如下:

TCP传输和UDP不一样,TCP传输是流式的,必须先建立连接,然后数据流沿已连接的线路(虚电路)传输。因此TCP的数据流不会像UDP数据报一样,每个数据报都要包含目标地址和端口,因为每个数据报要单独路由。TCP传输则只需要在建立连接时指定目标地址和端口就可以了。

形象的讲,TCP就像打电话,UDP就像发电报。宏观上来看UDP是不分客户端和服务端的。通信双方是平等的。微观上来讲只相对一个报文,发送端是客户端,监听端是服务端。发送端把数据报发给路由器就像把电报发给了邮局,后面的事情就是发送者无法控制,也无从知晓的了。所以说是不可靠的,可能会出现报文丢失而无从知晓。就像每张电报都要有收件人一样,每个数据报都要有目的地址和端口。

而TCP每次连接都是分客户端和服务端的。连接的发起者(相当与拨号打电话的人)是客户端,监听者(相当于在电话边等着接电话的人)是服务端。发起者指定要连接的服务器地址和端口(相当于拨号),监听者通过和发起者三次握手建立连接(相当于听到电话响去接电话)。建立连接后双方可以互相发送和接受数据(打电话)。

Java如何操作Socket?

值得一提的是,Java分别为TCP和UDP提供了相应的类,TCP是java.NET中提供了两个类Socket和ServerSocket,分别用来表示双向连接的客户端和服务端。这是两个封装得非常好的类,使用起来很方便!UDP是java.Net.DatagramSocket.

127.0.0.1是回路地址,用于测试,相当于localhost本机地址,没有网卡,不设DNS都可以访问,端口地址在0~65535之间,其中0~1023之间的端口是用于一些知名的网络服务和应用,用户的普通网络应用程序应该使用1024以上的端口.

Socket通信模型如下:

服务器,使用ServerSocket监听指定的端口,端口可以随意指定(由于1024以下的端口通常属于保留端口,在一些操作系统中不可以随意使用,所以建议使用大于1024的端口),等待客户连接请求,客户连接后,会话产生;在完成会话后,关闭连接。

客户端,使用Java socket通信对网络上某一个服务器的某一个端口发出连接请求,一旦连接成功,打开会话;会话完成后,关闭Socket。客户端不需要指定打开的端口,通常临时的、动态的分配一个1024以上的端口。

TCP网络连接模型:

Android客户端程序代分析:

UploadActivity.java  

package com.android.upload; 
import java.io.File;  
import java.io.OutputStream;  
import java.io.PushbackInputStream;  
import java.io.RandomAccessFile;  
import java.net.Socket;  
  
import android.app.Activity;  
import android.os.Bundle;  
import android.os.Environment;  
import android.os.Handler;  
import android.os.Message;  
import android.view.View;  
import android.view.View.OnClickListener; 
import android.widget.Button;  
import android.widget.EditText;  
import android.widget.ProgressBar;  
import android.widget.TextView;  
import android.widget.Toast;  
  
import com.android.service.UploadLogService;  
import com.android.socket.utils.StreamTool; 
 
  
public class UploadActivity extends Activity {  
  private EditText filenameText;  
  private TextView resulView;  
  private ProgressBar uploadbar;  
  private UploadLogService logService;  
  private boolean start=true; 
  private Handler handler = new Handler(){  
    @Override  
    public void handleMessage(Message msg) {  
      int length = msg.getData().getInt("size");  
      uploadbar.setProgress(length);  
      float num = (float)uploadbar.getProgress()/(float)uploadbar.getMax();  
      int result = (int)(num * 100);  
      resulView.setText(result+ "%");  
      if(uploadbar.getProgress()==uploadbar.getMax()){  
        Toast.makeText(UploadActivity.this, R.string.success, 1).show();  
      }  
    }  
  };  
    
  @Override  
  public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.main);  
      
    logService = new UploadLogService(this);  
    filenameText = (EditText)this.findViewById(R.id.filename);  
    uploadbar = (ProgressBar) this.findViewById(R.id.uploadbar);  
    resulView = (TextView)this.findViewById(R.id.result);  
    Button button =(Button)this.findViewById(R.id.button);  
    Button button1 =(Button)this.findViewById(R.id.stop);  
    button1 .setOnClickListener(new OnClickListener() { 
       
      @Override 
      public void onClick(View v) { 
        start=false; 
         
      } 
    }); 
    button.setOnClickListener(new View.OnClickListener() {  
      @Override  
      public void onClick(View v) {  
        start=true; 
        String filename = filenameText.getText().toString();  
        if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){  
          File uploadFile = new File(Environment.getExternalStorageDirectory(), filename);  
          if(uploadFile.exists()){  
            uploadFile(uploadFile);  
          }else{  
            Toast.makeText(UploadActivity.this, R.string.filenotexsit, 1).show();  
          }  
        }else{  
          Toast.makeText(UploadActivity.this, R.string.sdcarderror, 1).show();  
        }  
      }  
    });  
  }  
  /** 
   * 上传文件 
   * @param uploadFile 
   */  
  private void uploadFile(final File uploadFile) {  
    new Thread(new Runnable() {       
      @Override  
      public void run() {  
        try {  
          uploadbar.setMax((int)uploadFile.length());  
          String souceid = logService.getBindId(uploadFile);  
          String head = "Content-Length="+ uploadFile.length() + ";filename="+ uploadFile.getName() + ";sourceid="+  
            (souceid==null? "" : souceid)+"\r\n";  
          Socket socket = new Socket("192.168.1.78",7878);  
          OutputStream outStream = socket.getOutputStream();  
          outStream.write(head.getBytes());  
            
          PushbackInputStream inStream = new PushbackInputStream(socket.getInputStream());    
          String respOnse= StreamTool.readLine(inStream);  
          String[] items = response.split(";");  
          String respOnseid= items[0].substring(items[0].indexOf("=")+1);  
          String position = items[1].substring(items[1].indexOf("=")+1);  
          if(souceid==null){//代表原来没有上传过此文件,往数据库添加一条绑定记录  
            logService.save(responseid, uploadFile);  
          }  
          RandomAccessFile fileOutStream = new RandomAccessFile(uploadFile, "r");  
          fileOutStream.seek(Integer.valueOf(position));  
          byte[] buffer = new byte[1024];  
          int len = -1;  
          int length = Integer.valueOf(position);  
          while(start&&(len = fileOutStream.read(buffer)) != -1){  
            outStream.write(buffer, 0, len);  
            length += len;  
            Message msg = new Message();  
            msg.getData().putInt("size", length);  
            handler.sendMessage(msg);  
          }  
          fileOutStream.close();  
          outStream.close();  
          inStream.close();  
          socket.close();  
          if(length==uploadFile.length()) logService.delete(uploadFile);  
        } catch (Exception e) {  
          e.printStackTrace();  
        }  
      }  
    }).start();  
  }  
}

StreamTool.java  

package com.android.socket.utils; 
 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PushbackInputStream; 
 
public class StreamTool { 
    
   public static void save(File file, byte[] data) throws Exception { 
     FileOutputStream outStream = new FileOutputStream(file); 
     outStream.write(data); 
     outStream.close(); 
   } 
    
   public static String readLine(PushbackInputStream in) throws IOException { 
      char buf[] = new char[128]; 
      int room = buf.length; 
      int offset = 0; 
      int c; 
loop:    while (true) { 
        switch (c = in.read()) { 
          case -1: 
          case '\n': 
            break loop; 
          case '\r': 
            int c2 = in.read(); 
            if ((c2 != '\n') && (c2 != -1)) in.unread(c2); 
            break loop; 
          default: 
            if (--room <0) { 
              char[] lineBuffer = buf; 
              buf = new char[offset + 128]; 
              room = buf.length - offset - 1; 
              System.arraycopy(lineBuffer, 0, buf, 0, offset); 
               
            } 
            buf[offset++] = (char) c; 
            break; 
        } 
      } 
      if ((c == -1) && (offset == 0)) return null; 
      return String.copyValueOf(buf, 0, offset); 
  } 
    
  /** 
  * 读取流 
  * @param inStream 
  * @return 字节数组 
  * @throws Exception 
  */ 
  public static byte[] readStream(InputStream inStream) throws Exception{ 
      ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); 
      byte[] buffer = new byte[1024]; 
      int len = -1; 
      while( (len=inStream.read(buffer)) != -1){ 
        outSteam.write(buffer, 0, len); 
      } 
      outSteam.close(); 
      inStream.close(); 
      return outSteam.toByteArray(); 
  } 
}

UploadLogService.java  

package com.android.service; 
 
import java.io.File; 
 
import android.content.Context; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
 
public class UploadLogService { 
  private DBOpenHelper dbOpenHelper; 
   
  public UploadLogService(Context context){ 
    this.dbOpenHelper = new DBOpenHelper(context); 
  } 
   
  public void save(String sourceid, File uploadFile){ 
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); 
    db.execSQL("insert into uploadlog(uploadfilepath, sourceid) values(?,?)", 
        new Object[]{uploadFile.getAbsolutePath(),sourceid}); 
  } 
   
  public void delete(File uploadFile){ 
    SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); 
    db.execSQL("delete from uploadlog where uploadfilepath=?", new Object[]{uploadFile.getAbsolutePath()}); 
  } 
   
  public String getBindId(File uploadFile){ 
    SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); 
    Cursor cursor = db.rawQuery("select sourceid from uploadlog where uploadfilepath=?",  
        new String[]{uploadFile.getAbsolutePath()}); 
    if(cursor.moveToFirst()){ 
      return cursor.getString(0); 
    } 
    return null; 
  } 
}

DBOpenHelper.java  

package com.android.service; 
 
import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteOpenHelper; 
 
public class DBOpenHelper extends SQLiteOpenHelper { 
 
  public DBOpenHelper(Context context) { 
    super(context, "upload.db", null, 1); 
  } 
 
  @Override 
  public void onCreate(SQLiteDatabase db) { 
    db.execSQL("CREATE TABLE uploadlog (_id integer primary key autoincrement, uploadfilepath varchar(100), sourceid varchar(10))"); 
  } 
 
  @Override 
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 
    db.execSQL("DROP TABLE IF EXISTS uploadlog"); 
    onCreate(db);     
  } 
 
}

main.xml  

 
 
 
   
   
     
  

AndroidManifest.xml  

 
 
 
   
 
   
     
       
         
 
         
       
     
   
   
   
   
   
   
   

Java服务端:

SocketServer.javapackage com.android.socket.server; 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.OutputStream; 
import java.io.PushbackInputStream; 
import java.io.RandomAccessFile; 
import java.net.ServerSocket; 
import java.net.Socket; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.HashMap; 
import java.util.Map; 
import java.util.Properties; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors; 
 
import com.android.socket.utils.StreamTool; 
 
public class SocketServer { 
  private String uploadPath="D:/uploadFile/"; 
  private ExecutorService executorService;// 线程池 
  private ServerSocket ss = null; 
  private int port;// 监听端口 
  private boolean quit;// 是否退出 
  private Map datas = new HashMap();// 存放断点数据,最好改为数据库存放 
 
  public SocketServer(int port) { 
    this.port = port; 
    // 初始化线程池 
    executorService = Executors.newFixedThreadPool(Runtime.getRuntime() 
        .availableProcessors() * 50); 
  } 
 
  // 启动服务 
  public void start() throws Exception { 
    ss = new ServerSocket(port); 
    while (!quit) { 
      Socket socket = ss.accept();// 接受客户端的请求 
      // 为支持多用户并发访问,采用线程池管理每一个用户的连接请求 
      executorService.execute(new SocketTask(socket));// 启动一个线程来处理请求 
    } 
  } 
 
  // 退出 
  public void quit() { 
    this.quit = true; 
    try { 
      ss.close(); 
    } catch (IOException e) { 
      e.printStackTrace(); 
    } 
  } 
 
  public static void main(String[] args) throws Exception { 
    SocketServer server = new SocketServer(7878); 
    server.start(); 
  } 
 
  private class SocketTask implements Runnable { 
    private Socket socket; 
 
    public SocketTask(Socket socket) { 
      this.socket = socket; 
    } 
 
    @Override 
    public void run() { 
      try { 
        System.out.println("accepted connenction from " 
            + socket.getInetAddress() + " @ " + socket.getPort()); 
        PushbackInputStream inStream = new PushbackInputStream( 
            socket.getInputStream()); 
        // 得到客户端发来的第一行协议数据:Content-Length=143253434;filename=xxx.3gp;sourceid= 
        // 如果用户初次上传文件,sourceid的值为空。 
        String head = StreamTool.readLine(inStream); 
        System.out.println(head); 
        if (head != null) { 
          // 下面从协议数据中读取各种参数值 
          String[] items = head.split(";"); 
          String filelength = items[0].substring(items[0].indexOf("=") + 1); 
          String filename = items[1].substring(items[1].indexOf("=") + 1); 
          String sourceid = items[2].substring(items[2].indexOf("=") + 1); 
          Long id = System.currentTimeMillis(); 
          FileLog log = null; 
          if (null != sourceid && !"".equals(sourceid)) { 
            id = Long.valueOf(sourceid); 
            log = find(id);//查找上传的文件是否存在上传记录 
          } 
          File file = null; 
          int position = 0; 
          if(log==null){//如果上传的文件不存在上传记录,为文件添加跟踪记录 
            String path = new SimpleDateFormat("yyyy/MM/dd/HH/mm").format(new Date()); 
            File dir = new File(uploadPath+ path); 
            if(!dir.exists()) dir.mkdirs(); 
            file = new File(dir, filename); 
            if(file.exists()){//如果上传的文件发生重名,然后进行改名 
              filename = filename.substring(0, filename.indexOf(".")-1)+ dir.listFiles().length+ filename.substring(filename.indexOf(".")); 
              file = new File(dir, filename); 
            } 
            save(id, file); 
          }else{// 如果上传的文件存在上传记录,读取上次的断点位置 
            file = new File(log.getPath());//从上传记录中得到文件的路径 
            if(file.exists()){ 
              File logFile = new File(file.getParentFile(), file.getName()+".log"); 
              if(logFile.exists()){ 
                Properties properties = new Properties(); 
                properties.load(new FileInputStream(logFile)); 
                position = Integer.valueOf(properties.getProperty("length"));//读取断点位置 
              } 
            } 
          } 
           
          OutputStream outStream = socket.getOutputStream(); 
          String respOnse= "sourceid="+ id+ ";position="+ position+ "\r\n"; 
          //服务器收到客户端的请求信息后,给客户端返回响应信息:sourceid=1274773833264;position=0 
          //sourceid由服务生成,唯一标识上传的文件,position指示客户端从文件的什么位置开始上传 
          outStream.write(response.getBytes()); 
           
          RandomAccessFile fileOutStream = new RandomAccessFile(file, "rwd"); 
          if(position==0) fileOutStream.setLength(Integer.valueOf(filelength));//设置文件长度 
          fileOutStream.seek(position);//移动文件指定的位置开始写入数据 
          byte[] buffer = new byte[1024]; 
          int len = -1; 
          int length = position; 
          while( (len=inStream.read(buffer)) != -1){//从输入流中读取数据写入到文件中 
            fileOutStream.write(buffer, 0, len); 
            length += len; 
            Properties properties = new Properties(); 
            properties.put("length", String.valueOf(length)); 
            FileOutputStream logFile = new FileOutputStream(new File(file.getParentFile(), file.getName()+".log")); 
            properties.store(logFile, null);//实时记录文件的最后保存位置 
            logFile.close(); 
          } 
          if(length==fileOutStream.length()) delete(id); 
          fileOutStream.close();          
          inStream.close(); 
          outStream.close(); 
          file = null; 
        } 
      } catch (Exception e) { 
        e.printStackTrace(); 
      } finally { 
        try { 
          if(socket != null && !socket.isClosed()) socket.close(); 
        } catch (IOException e) {} 
      } 
    } 
 
  } 
 
  public FileLog find(Long sourceid) { 
    return datas.get(sourceid); 
  } 
 
  // 保存上传记录 
  public void save(Long id, File saveFile) { 
    // 日后可以改成通过数据库存放 
    datas.put(id, new FileLog(id, saveFile.getAbsolutePath())); 
  } 
 
  // 当文件上传完毕,删除记录 
  public void delete(long sourceid) { 
    if (datas.containsKey(sourceid)) 
      datas.remove(sourceid); 
  } 
 
  private class FileLog { 
    private Long id; 
    private String path; 
     
    public FileLog(Long id, String path) { 
      super(); 
      this.id = id; 
      this.path = path; 
    } 
 
    public Long getId() { 
      return id; 
    } 
 
    public void setId(Long id) { 
      this.id = id; 
    } 
 
    public String getPath() { 
      return path; 
    } 
 
    public void setPath(String path) { 
      this.path = path; 
    } 
 
  } 
}
ServerWindow.javapackage com.android.socket.server; 
 
import java.awt.BorderLayout; 
import java.awt.Frame; 
import java.awt.Label; 
import java.awt.event.WindowEvent; 
import java.awt.event.WindowListener; 
 
public class ServerWindow extends Frame{ 
  private SocketServer server; 
  private Label label; 
   
  public ServerWindow(String title){ 
    super(title); 
    server = new SocketServer(7878); 
    label = new Label(); 
    add(label, BorderLayout.PAGE_START); 
    label.setText("服务器已经启动"); 
    this.addWindowListener(new WindowListener() { 
      @Override 
      public void windowOpened(WindowEvent e) { 
        new Thread(new Runnable() {      
          @Override 
          public void run() { 
            try { 
              server.start(); 
            } catch (Exception e) { 
              e.printStackTrace(); 
            } 
          } 
        }).start(); 
      } 
       
      @Override 
      public void windowIconified(WindowEvent e) { 
      } 
       
      @Override 
      public void windowDeiconified(WindowEvent e) { 
      } 
       
      @Override 
      public void windowDeactivated(WindowEvent e) { 
      } 
       
      @Override 
      public void windowClosing(WindowEvent e) { 
         server.quit(); 
         System.exit(0); 
      } 
       
      @Override 
      public void windowClosed(WindowEvent e) { 
      } 
       
      @Override 
      public void windowActivated(WindowEvent e) { 
      } 
    }); 
  } 
  /** 
   * @param args 
   */ 
  public static void main(String[] args) { 
    ServerWindow window = new ServerWindow("文件上传服务端");  
    window.setSize(300, 300);  
    window.setVisible(true); 
  } 
 
}
StreamTool.javapackage com.android.socket.utils; 
 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PushbackInputStream; 
 
public class StreamTool { 
    
   public static void save(File file, byte[] data) throws Exception { 
     FileOutputStream outStream = new FileOutputStream(file); 
     outStream.write(data); 
     outStream.close(); 
   } 
    
   public static String readLine(PushbackInputStream in) throws IOException { 
      char buf[] = new char[128]; 
      int room = buf.length; 
      int offset = 0; 
      int c; 
loop:    while (true) { 
        switch (c = in.read()) { 
          case -1: 
          case '\n': 
            break loop; 
          case '\r': 
            int c2 = in.read(); 
            if ((c2 != '\n') && (c2 != -1)) in.unread(c2); 
            break loop; 
          default: 
            if (--room <0) { 
              char[] lineBuffer = buf; 
              buf = new char[offset + 128]; 
              room = buf.length - offset - 1; 
              System.arraycopy(lineBuffer, 0, buf, 0, offset); 
               
            } 
            buf[offset++] = (char) c; 
            break; 
        } 
      } 
      if ((c == -1) && (offset == 0)) return null; 
      return String.copyValueOf(buf, 0, offset); 
  } 
    
  /** 
  * 读取流 
  * @param inStream 
  * @return 字节数组 
  * @throws Exception 
  */ 
  public static byte[] readStream(InputStream inStream) throws Exception{ 
      ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); 
      byte[] buffer = new byte[1024]; 
      int len = -1; 
      while( (len=inStream.read(buffer)) != -1){ 
        outSteam.write(buffer, 0, len); 
      } 
      outSteam.close(); 
      inStream.close(); 
      return outSteam.toByteArray(); 
  } 
 
}

运行效果如下:

Android前端控制:

后台监控日志:

下载后的文件路径:

 


推荐阅读
  • fileuploadJS@sectionscripts{<scriptsrc~Contentjsfileuploadvendorjquery.ui.widget.js ... [详细]
  • RouterOS 5.16软路由安装图解教程
    本文介绍了如何安装RouterOS 5.16软路由系统,包括系统要求、安装步骤和登录方式。同时提供了详细的图解教程,方便读者进行操作。 ... [详细]
  • 本文介绍了解决Netty拆包粘包问题的一种方法——使用特殊结束符。在通讯过程中,客户端和服务器协商定义一个特殊的分隔符号,只要没有发送分隔符号,就代表一条数据没有结束。文章还提供了服务端的示例代码。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • Mac OS 升级到11.2.2 Eclipse打不开了,报错Failed to create the Java Virtual Machine
    本文介绍了在Mac OS升级到11.2.2版本后,使用Eclipse打开时出现报错Failed to create the Java Virtual Machine的问题,并提供了解决方法。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • 本文介绍了计算机网络的定义和通信流程,包括客户端编译文件、二进制转换、三层路由设备等。同时,还介绍了计算机网络中常用的关键词,如MAC地址和IP地址。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Android源码深入理解JNI技术的概述和应用
    本文介绍了Android源码中的JNI技术,包括概述和应用。JNI是Java Native Interface的缩写,是一种技术,可以实现Java程序调用Native语言写的函数,以及Native程序调用Java层的函数。在Android平台上,JNI充当了连接Java世界和Native世界的桥梁。本文通过分析Android源码中的相关文件和位置,深入探讨了JNI技术在Android开发中的重要性和应用场景。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文介绍了包的基础知识,包是一种模块,本质上是一个文件夹,与普通文件夹的区别在于包含一个init文件。包的作用是从文件夹级别组织代码,提高代码的维护性。当代码抽取到模块中后,如果模块较多,结构仍然混乱,可以使用包来组织代码。创建包的方法是右键新建Python包,使用方式与模块一样,使用import来导入包。init文件的使用是将文件夹变成一个模块的方法,通过执行init文件来导入包。一个包中通常包含多个模块。 ... [详细]
  • 解决浏览器打开网页后提示“dns_probe_possible 怎么解决”的方法
    在使用浏览器进行网上冲浪的时候遇到故障是一件很常见的事情,很多用户都遇到过系统提示:dns_probe_possible。从提示中可以看出和DNS是有一定的关系的,经过小编测试之后 ... [详细]
  • pc电脑如何投屏到电视?DLNA主要步骤通过DLNA连接,使用WindowsMediaPlayer的流媒体播放举例:电脑和电视机都是连接的 ... [详细]
  • 用ESP32与Python实现物联网(IoT)火焰检测报警系统
    下图是本案例除硬件连线外的3步导学开发过程,每个步骤中实现的功能请参考图中的说明。在硬件连线完成之后我们建议您先使用“一分钟上云体验”功能预先体验本案例的实际运行效果 ... [详细]
  • 开发笔记:UEditor调用上传图片上传文件等模块
    1、引入ue相关文件,写好初始代码为了更好的封装整一个单独的插件,这里我们要做到示例化ue后隐藏网页中的编辑窗口,并移除焦点。 ... [详细]
author-avatar
窝窝笑丫
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有