昨天一个同事请我一个问题,在下列代码中如何将
  InputStream is 这个元素只初始化一次呢?
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import lrapi.lr;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import com.google.common.io.ByteStreams;
import com.jd.jfs.JingdongFileSystem;
public class Actions
{
File file = new File("C:/8K.file");
InputStream is =null; // 返回一个byte数组<pre code_snippet_id="145362" snippet_file_name="blog_20140107_2_8044261" name="code" class="java">         byte[] fileBytes = new byte[(int) file.length()];
// 创建一个数据来保存文件数据
JingdongFileSystem jfs =new JingdongFileSystem();
public int init() throws Throwable {
is = new FileInputStream(file);
ByteStreams.readFully(is, fileBytes);
is.close();
//jfs = new JingdongFileSystem();
return 0;
} //end of init
public int action() throws Throwable {
try {
lr.start_transaction("jfs-w");
String key = jfs.writeBytes(fileBytes);
//上传
System.out.println(key);
} catch (Exception e) {
e.printStackTrace();
}
lr.end_transaction("jfs-w", lr.AUTO);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}