BufferedOutputStream .write(byte[] b,int off, int len)的问题,求解答
File mfile = new File(mfilepath);
os.println(mfile.getName());
os.flush();
System.out.println("@send name:"+mfile.getName());
line =is.readLine();
if(line.equals("file not exist")){
System.out.println("file no exist");
int mfilelength = (int)mfile.length();
System.out.println("file length:"+mfilelength);
os.println(mfilelength);
os.flush();
System.out.println("@send length:"+mfilelength);
FileInputStream fo = new FileInputStream(mfile);
BufferedInputStream in = new BufferedInputStream(fo);
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
byte s_array[] = new byte[mfilelength];
System.out.println("array ready");
in.read(s_array,0,mfilelength);
out.write(s_array,0,mfilelength);
s_array = null;
System.out.println("send "+mfile.getName()+" over");
String mfile_name = mfile.getName();
String mlrc_name = mfile_name.substring(0,mfile_name.length()-3)+"lrc";
String mparentpath = mfile.getParent();
System.out.println(mparentpath+"\\"+mlrc_name);
File mlrcfile = new File(mparentpath+"\\"+mlrc_name);
if(!mlrcfile.exists()){
os.println("no lrcfile");
os.flush();
System.out.println("send no lrcfile"); }
else{
FileInputStream fr = new FileInputStream(mlrcfile);
BufferedInputStream inr = new BufferedInputStream(fr);
BufferedOutputStream outr = new BufferedOutputStream(socket.getOutputStream());
os.println("lrcfile");
os.flush();
System.out.println("send lrcfile");
int lrc_length = (int)mlrcfile.length();
os.println(lrc_length);
os.flush();
System.out.println("@send length:"+lrc_length);
byte s_array1[] = new byte[lrc_length];
System.out.println("array1 ready");
for(int i=0;i<3;i++){
System.out.println("after read");
System.out.println(s_array1[i]);
}
inr.read(s_array1,0,lrc_length);
//inr.readLine();
for(int i=0;i<3;i++){
System.out.println("after read");
//System.out.println(s_array1[1]+" "+s_array[2]+" "+s_array[3]);
System.out.println(s_array1[i]);
}
outr.write(s_array1);
//os.println("big sb");
//os.flush();
System.out.println("send over");
line = is.readLine();
//s_array1 = null;
System.out.println("send "+mlrcfile.getName()+" over");
sleep(1000);
inr.close();
fr.close();
outr.close();
}
in.close();
fo.close();
out.close();
lrc文件因为太小客户端就是收不到,本人学java三周,实在找不到原因,求各位大神指点,感激不尽啊