public static void forcdt(String dir){
InputStream in = null;
OutputStream out = null;
File localFile = new File(dir);
try{
//创建file类 传入本地文件路径
//获得本地文件的名字
String fileName = localFilegetName();
//将本地文件的名字和远程目录的名字拼接在一起
//确保上传后的文件于本地文件名字相同
SmbFile remoteFile = new SmbFile("smb://administrator:admin@10001/e$/aa/");
//创建读取缓冲流把本地的文件与程序连接在一起
in = new BufferedInputStream(new FileInputStream(localFile));
//创建一个写出缓冲流(注意jcifs-1315jar包 类名为Smb开头的类为控制远程共享计算机"io"包)
//将远程的文件路径传入SmbFileOutputStream中 并用 缓冲流套接
out = new BufferedOutputStream(new SmbFileOutputStream(remoteFile+"/"+fileName));
//创建中转字节数组
byte[] buffer = new byte[1024];
while(inread(buffer)!=-1){//in对象的read方法返回-1为 文件以读取完毕
outwrite(buffer);
buffer = new byte[1024];
}
}catch(Exception e){
eprintStackTrace();
}finally{
try{
//注意用完 *** 作io对象的方法后关闭这些资源,走则 造成文件上传失败等问题。!
outclose();
inclose();
}catch(Exception e){
eprintStackTrace();}
}
}
你在逗我,怎么可能直接用程序直接写入另一个服务器。
我的思路是(没有试验过)
转换为为二进制文件进行上传到另一个服务器进行处理保存
转换为base64 用curl请求服务器进行处理
模拟表单请求
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)