文件保存、html标签file自定义test和button(笔记)

获取一个文件保存到本地的另一个目录,代码如下:

 

 

public static void main(String[] args) {
		String photoUrl ="file:///f:/xx.wav";		
		String filePath = "E:/voc//Content/";
		String fileName=filePath+"tt.wav";		
		  try { 
			    URL url = new URL(photoUrl); 
			    FileURLConnection connection = (FileURLConnection) url.openConnection();
			    DataInputStream in = new DataInputStream(connection.getInputStream()); 
			    DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
			    byte[] buffer = new byte[4096];
			    int count = 0;
			    while ((count = in.read(buffer)) > 0) { 
			    out.write(buffer, 0, count);
			    }
			    out.close();
			    in.close();			   
			  }
			  catch (Exception e) { 
			    e.printStackTrace();
			  } 
	}

 

 

html的file标签,自定义button按钮和text文本,这样就可以给text赋值和设置button的样式,代码如下:

<input type="file" id="upVocFile"  name="upVocFile" style="display:none;"/>
<input type="text" name="file" id="file" disabled="disabled"  size="50" />
<input type="button" id="uploadBtn" name="uploadBtn" onClick="upVocFile.disabled=false;upVocFile.click();file.value=upVocFile.value;upVocFile.disabled=false;" value="浏览..." />

 

 

点击type="file"文件“浏览”按钮后,触发事件的写法如下:

 

<html >
<head>
</head>
<script type="text/javascript">
function test(){
	alert("ccc")
}
</script>
<body>
<input type="file" id="upVocFile" name="upVocFile"onchange="subf.click();"/>
<input type="button" value="上传" id="subf" style="display:none" onclick="test()">
</body>
</html>
<html >
<head>
</head>
<script type="text/javascript">
function setTelNoS(){
	alert("ccc")
}
</script>
<body>
<input type="file" id="telNoFile" name="telNoFile" size="45" onchange="javascript :setTelNoS();"/></body>
</html>

 

 _fileObj.outerHTML =_fileObj.outerHTML  能清空input中file控件的值

你可能感兴趣的:(JavaScript,html,F#)