听起来好象不难,可是不知道你的要求到底是什么?
方法中提供两个参数:什么类型?
现有这样的BUFFER: 哪来的?第一个参数?如果这个BUFFER 存储了文件名,那还要第二个参数干什么?
方法中提供两个参数:什么类型?
现有这样的BUFFER: 哪来的?第一个参数?如果这个BUFFER 存储了文件名,那还要第二个参数干什么?
解决方案 »
- 报名参加了学校组织的视觉机器人大赛,但不知道从哪学起,还望高手指点!!
- java 泛型
- 数组中提取数据
- 关于main函数中的args[] 问题。高手指教!
- 已二进制方式读取文件并返回给发送者响应的问题(见内)
- JSTL中c:forEach标签的varStatus问题?在线等!!
- 40分求解关于TextArera的问题!!
- [JNI]请问如何用JNI将Java下的取得一个字符串传到C里,我现在已经能用java调用c生成的.dll文件
- 我想做一个多媒体课件系统,大家多支持,多给点思路
- 请问在APPLET中我重新编译一个CLASS,为什么在网页中刷新会没有改变呢?
- 如何改变java swing GUI外观?
- 大家帮帮忙,我的邮件被删除了
BUFFER是别的地方的不用管,第一个参数就是这个BUFFER的名字就可以了。
第二个参数就是另外想要存的目录位置。
谢谢,急啊!
public static void makeFile( StringBuffer sb, String path ){
String str = sb.toString();
String name = str.substring( 0, 80 ).trim();
String content = str.substring( 80 );
String filePath = path;
File myFilePath = new File( filePath );
if( !myFilePath.exists() ){
myFilePath.mkdirs();
System.out.println( "mkdir() " );
}
File myFile = new File( filePath, name );
try{
BufferedWriter bw = new BufferedWriter( new FileWriter( myFile ) );
bw.write( content );
bw.close();
}catch( IOException ioe ){
System.out.println( "Wrong ........." );
}
}
public static void main( String[] args ){
StringBuffer sb = new StringBuffer();
sb.append( " " );
sb.append( " 3fg.txt" );
sb.append( " " );
sb.append( " " );
sb.append( " " );
sb.append( " " );
sb.append( " " );
sb.append( " " );
sb.append( "wouieoeoeo" );
String path = "d:" + File.separator + "abc" + File.separator + "efg";
System.out.println( path );
test3.makeFile( sb, path );
}
}
public class Test58 { public Test58(){
byte[] b=new byte[300];
b[0]=(int)'a';
b[1]=(int)'b';
for(int i=80;i<300;i++){
b[i]=(int)'1';
}
amjn(b,"c:");
} public void amjn(byte[] buffer,String dir){
byte[] fileName=new byte[80];
for(int i=0;i<80;i++){
fileName[i]=buffer[i];
}
String file=new String(fileName,0,fileName.length);
try{
FileOutputStream fileOut = new FileOutputStream(dir + File.separator+file);
fileOut.write(buffer,80,buffer.length-80);
System.out.println(buffer.length);
fileOut.flush();
fileOut.close();
}
catch(IOException e){
e.printStackTrace();
}
} public static void main(String[] args){
new Test58();
}
}