public class AndroidClientActivity extends Activity implements OnClickListener{
private Button btn1;
private String filePath = "/sdcard/image/";
private String fileName = "bln.jpg";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button)this.findViewById(R.id.btn1);
btn1.setOnClickListener(this);
}
public void onClick(View v) {
try {
// 建立和服务器的连接
Socket socket = new Socket("192.168.0.10", 6666);
// 创建FilePojo对象
FilePojo fpo = new FilePojo();
// 设定文件名
fpo.setFileName(fileName);
// 设定文件大小
File f = new File(filePath + fileName);
long fileLength = f.length();
fpo.setFileLength(fileLength);
// 读取文件内容,并将其转换为byte[]
FileInputStream fis = new FileInputStream(filePath + fileName);
byte[] fileContent = new byte[(int) fileLength];
fis.read(fileContent, 0, (int) fileLength);
fpo.setFileContent(fileContent);
// 将FilePojo对象fpo写到Socket client指定的输出流
long start = System.currentTimeMillis();
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(fpo);
long end = System.currentTimeMillis();
Toast.makeText(this.getApplicationContext(), "It takes " + (end - start) + "ms", Toast.LENGTH_LONG).show();
oos.flush();
oos.close();
}
catch(Exception ioe) {
ioe.printStackTrace();
} }}
下面就是在AndroidManifest.xml中增加permission权限如下:
<!-- 表示该程序可以读取sd卡上的内容 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>.
<!-- 表示该程序可以联网 -->
<uses-permission android:name="android.permission.INTERNET" />
4、运行。
先运行服务端ObjectServer,再在Android手机上运行客户端AndroidClientActivity 。
分享到:
相关推荐
Kotlin cross-platform / multi-format reflectionless serialization Kotlin serialization consists of a compiler plugin, which automatically produces visitor code for classes, and runtime library, ...
sirenix.serialization.dll
System.Runtime.Serialization.DLL
word\Excel文件等),这里只提供一个简单的文本文件,应用该文件我做出了把任何文件存储为二进制,而读取存储的二进制文件时报了一异常信息:异常类型: System.Runtime.Serialization.Serialization 异常消息: 二...
资源来自pypi官网。 资源全名:oslo.serialization-2.2.0.tar.gz
System.Runtime.Serialization.dll System.Runtime.Serialization.dll System.Runtime.Serialization.dll
JAX-RS Kotlinx Serialization A message body reader/writer and parameter converter which uses kotlinx-serialization. Usage val resourceConfig = new ResourceConfig(); resourceConfig.register(Json....
hystrix-serialization-1.5.18.jar
- 整个代码由一个头文件组成 json.hpp,没有子项目,没有依赖关系,没有复杂的构建系统,使用起来非常方便 - 语法直观,就像写普通的c++代码 ...改良自德国大牛nlohmann的开源项目,可以二次封装在dll中。
kotlinx-serialization-compiler-plugin.jar
数据的序列化和反序列化 Serialization DeSerialization
akka-kryo-serialization, 基于Kryo的Akka序列化 akka-kryo-serialization-- Scala 和Akka基于kryo的序列化程序这个库为 Scala 和Akka提供定制的基于kryo的序列化程序。 它可以用于更高效的akka远程处理。它还可以...
.net2.0版本的json操作类 ...System.Web.Script.Serialization的json操作类,位于3.0以上的System.Web.Extensions类库中. 本项目是从System.Web.Extensions中剥离出System.Web.Script.Serialization的完整项目
it also makes (de)serialization painless. It wraps around the well-known org.json classes (JSONObject, JSONArray, etc.) which also happen to be included in the Android SDK. As we all know, those ...
Paper is a fast NoSQL data storage for Android that lets you save/restore Java/Kotlin objects using efficient Kryo serialization. Class structure changes handled automatically. What's new in 2.1 Get...
此压缩包包含12个项目,每个项目都着重讲解Boost::Serialization一个方面的使用技巧,有详细的代码介绍具体使用方法。
该库向kotlinx.serialization添加了YAML支持。 支持YAML 1.2版。 使用示例从YAML解析到Kotlin对象@Serializable数据类Team(val领导者:字符串,val成员:列表 )val input =“”“领导者:艾米(Amy)成员:-鲍勃-...
注意:JsonHelper需要引用System.Runtime.Serialization;需要有xml文件记录token和expiretime;只有发送消息;接收消息待上传。。。