Java中对文件的操作
Java中对文件的操作
java中提供了io类库,可以轻松的用java实现对文件的各种操作。下面就来说一下如何用java来实现这些操作。
1。新建目录
<%@
page contentType="text/html;charset=gb2312"%>
<%
String
filePath="c:/aaa/";
filePath=filePath.toString();//中文转换
java.io.File
myFilePath=new
java.io.File(filePath);
if(!myFilePath.exists())
myFilePath.mkdir();
%>
2。新建文件
<%@
page contentType="text/html;charset=gb2312"%>
<%@ page
import="java.io.*" %>
<%
String
filePath="c:/哈哈.txt";
filePath=filePath.toString();
File
myFilePath=new
File(filePath);
if(!myFilePath.exists())
myFilePath.createNewFile();
FileWriter
resultFile=new FileWriter(myFilePath);
PrintWriter myFile=new
PrintWriter(resultFile);
String strContent =
"中文测试".toString();
myFile.println(strContent);
resultFile.close();
%>
3。删除文件
<%@
page contentType="text/html;charset=gb2312"%>
<%
String
filePath="c:/支出证明单.xls";
filePath=filePath.toString();
java.io.File
myDelFile=new
java.io.File(filePath);
myDelFile.delete();
%>
4。文件拷贝
<%@
page contentType="text/html; charset=gb2312" %>
<%@ page
import="java.io.*" %>
<%
int bytesum=0;
int
byteread=0;
file://读到流中
InputStream inStream=new
FileInputStream("c:/aaa.doc");
FileOutputStream fs=new FileOutputStream(
"d:/aaa.doc");byte[] buffer =new byte[1444];
int length;
while
((byteread=inStream.read(buffer))!=-1)
{
out.println("<DT><B>"+byteread+"</B></DT>");
bytesum+=byteread;
System.out.println(bytesum);
fs.write(buffer,0,byteread);
}
inStream.close();
%>
5。整个文件夹拷贝
<%@
page contentType="text/html;charset=gb2312"%>
<%@ page
import="java.io.*" %>
<%String url1="C:/aaa";
String
url2="d:/java/";
(new File(url2)).mkdirs();
File[] file=(new
File(url1)).listFiles();
for(int
i=0;i<file.length;i++){
if(file.isFile()){
file.toString();
FileInp
相关文档:
List的用法
List包括List接口以及List接口的所有实现类。因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以List接口还提供了一些适合于自身的常用方法,如表1所示。
表1 List接口定义的常用方法及功能
从表1可以看出,List接口提供的适合于自身的 ......
今天放假,我一个在网上认识的朋友,今天来找我,他以前是搞VB开发的,今天32岁,工资是税后6K,在北京对于程序员也算是中等吧,他现在都感觉到了危机意识了,毕竟现在年龄在那儿去了,但是他的样子看起来却是非常的年青,真的很羡慕他!只不过对于程序员而言,我更佩服牛人。
哥们来了的原因,今天一直到下午的两点,都 ......
Java版俄罗斯方块
08年写的一个Java版俄罗斯方块程序
界面做的中规中矩,每种形状颜色都不相同
程序控制还可以,没什么大的Bug
消磨时间的时候可以Down下来玩玩
下载链接:http://download.csdn.net/source/2384193
菜单选项
也做了不少菜单选项
可自定义控制键,可设置单色彩色显示,可设置网格是否显示
关 ......
一、数组是什么?
1.基本概念:
Definition:数组就是相同类型元素的线性集合。
Array is a collection of the same data.
An array is object.
对数组的理解:
数组是一个对象,是一个指向数组的引用对象。
2.Syntax
Array Copy
二、为什么要使用数组?
......