flex上传数据RemoteObject 与java
flex代码:
<fx:Declarations>
<mx:RemoteObject
id="pencile"
destination="fcj"
result="testresult(event)"
endpoint="http://192.168.1.109:8080/remote/messagebroker/amf">
</mx:RemoteObject>
</fx:Declarations>
<fx:Script>
<![CDATA[
public function test():void
{
var bitmapData:BitmapData=new BitmapData(this.designArea.width, this.designArea.height,true,0x00ffffff);
bitmapData.draw(this.designArea);
var filecreat:FileCreateor=new FileCreateor();
imgs=filecreat.getImageBytes(bitmapData);
pencile.writeFile(imgs,this.saveimgpath,filename+".jpg");
}
public function testresult(event:ResultEvent):void
{
}
]]>
</fx:Script>
java代码:
/**
* 写二进制文件
*
* @param byteA
* 二进数组
* @param newpath
* 保存路径
* @param newfilename
* 保存的文件名
* @return 保存的文件名
*/
public String writeFile(byte[] byteA, String newpath,
String newfilename) {
FileOutputStream outStream = null;
BufferedWriter out=null;
try {
newpath = newpath.replace(File.separator, "/");
if (newpath.endsWith("/")) {
newpath = newpath.substring(0, newpath.length() - 1);
}
String filePathAndName=newpath + "/" + newfilename;
File myFilePath = new File(filePathAndName);
if (!myFilePath.exists()) {
createFolders(filePathAndName.substring(0, filePathAndName
.lastIndexOf("/")));
//myFilePath.createNewFile();
}
//writeText(newpath + "/" + newfilename, "", "");
RandomAccessFile randomFile = new RandomAccessFile(filePathAndName, "rw");
// 文件长度,字节数
long fileLength = randomFile.length();
//将写文件指针移到文件尾。
randomFile.seek(fileLength);
randomFile.write(byteA);
randomFile.close();
//out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newpath + "/" + newfilename,true)));
//out.wwrite(byteA);//write(byteA, 0, len);//write(byteA);
//out.flush();
} catch (Exception ex) {
newfilename = ex.getMessage();
} finally {
try {
if (outStream != null)
out.close();
} catch (IOException e) {
newfilename = "";
}
}
System.out.print(byteA.toString());
return newfilename;
}