网站首页 语言 会计 电脑 医学 资格证 职场 文艺体育 范文
当前位置:书香门第 > 计算机 > java语言

javaIO读和写和创建文件夹的基础简单操作

栏目: java语言 / 发布于: / 人气:7.07K

导语:Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的`多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。下面我们来看看javaIO读和写和创建文件夹的基础简单操作,希望对大家有所帮助。

javaIO读和写和创建文件夹的基础简单操作
Auto !important; width: auto !important; bottom: auto !important; float: none !important; height: auto !important; font-size: 1em !important; vertical-align: baseline !important; overflow: visible !important; right: auto !important; top: auto !important; left: auto !important; background-image: none; background-attachment: scroll; background-size: initial; background-origin: initial; background-clip: initial; background-position: 0% 0%; background-repeat: repeat;" class="firstRow">
1234567package e16; import ; import NotFoundException; import Reader; import Writer; import ception;
1public class FileUtil { public static final String PATH=roperty(""); public void cj(String path) { File file=new File(PATH+path); int index=xOf("."); if(index==-1) { if(!ts()) { rs(); } }else { int index2=IndexOf("/"); String string=path.substring(0, index2); if(!ts()) { File file2=new File(PATH+string); rs(); } } try { teNewFile(); } catch (IOException e) { // TODO Auto-generated catch block tStackTrace(); } } }

public class TestFileUtil {public static void main(String[] args) {

1//读和写的初始化 FileReader fileReader=null; FileWriter fileWriter=null; try {
1234567891011 //读和写的初始化 fileReader=new FileReader(file); ("/src/com/lanou/day18/"); fileWriter=new FileWriter(fileName); //将读出来的数据写入 int lenght=0; char[] context=new char[1024]; while((lenght=fileReader.read(context))!=-1) { e(context,0,lenght); }
1234567891011 //完成后刷新 h(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block tStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block tStackTrace(); }finally { if(fileWriter!=null) { try {
123456789101112 //关闭写入流 fileWriter.close(); } catch (IOException e) { // TODO Auto-generated catch block tStackTrace(); } } } }

Tags:javaIO 文件夹