public static void writeFile(String strUrl, String fileName) {
URL url = null
try {
url = new URL(strUrl)
} catch (MalformedURLException e2) {
e2.printStackTrace()
}
InputStream is = null
try {
is = url.openStream()
} catch (IOException e1) {
e1.printStackTrace()
}
OutputStream os = null
try {
os = new FileOutputStream( fileName)
int bytesRead = 0
byte[] buffer = new byte[8192]
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead)
}
System.out.println("者岁搏下载雀谈成功:"+strUrl)
} catch (FileNotFoundException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}
}
import java.io.Fileimport java.io.FileNotFoundException
import java.io.IOException
import java.io.RandomAccessFile
public class Io{
public static void main(String [] s){
File filename = new File("F:\\suncity.txt"仿链)
String filein="你好!备磨孙"
RandomAccessFile mm = null
try {
mm = new RandomAccessFile(filename,"rw")
mm.writeBytes(filein)
} catch (IOException e1) {
// TODO 自动生成游空 catch 块
e1.printStackTrace()
} finally{
if(mm!=null){
try {
mm.close()
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace()
}
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)