我想将我的 android .apk 文件从 java restful web 服务发送到我的客户端(浏览器)。我尝试使用波纹管代码。但它会生成一个名为“MyPath”的文件,没有任何文件扩展名(需要 .apk)。提前致谢
@Path("MyPath")
public class MyPathResource {
@Context
private UriInfo context;
/**
* Creates a new instance of MyPathResource
*/
public MyPathResource() {
}
@GET
@Produces("application/vnd.android.package-archive")
public File getFile() {
// return my file
return new File("E:\\CommandLineAndroidProjet1\\bin\\FirstCommandLineApp-release.apk");
}
}
最佳答案
尝试创建一个明确的javax.ws.core.Response
:
return Response.status(Response.Status.OK)
.entity(entity)
.header("Content-Disposition", "attachment; filename=" + fileName)
.build();
entity
是字节数组形式的文件,fileName
是后缀为 .apk
的文件名。
关于java - 从 REST Web 服务向客户端发送 .apk 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25717839/