Hi=(H(key) + di) MOD m,i=1,2,…,k(k<=m-1),其中H(key)为散列函数,m为散列表长,di为增量序列,可有下列三种取法:java
方向web
内容数组
字节流网络
字符流dom
public static void main(String[] args) throws Exception { try { //读取文件 FileReader reader = new FileReader("/Users/xutingyu/Documents/Tye/TestFile/tye.txt"); char[] array = new char[10]; int length = 0; while ((length = reader.read(array)) > 0) { //将一个字节数组array从0取到length,而后转换成String类型 System.out.print(new String(array, 0, length)); } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } }
public static void main(String[] args) { String str = "hudhkhdpidsjfpdsifjildsgjidgdfg\n123123123"; try { FileWriter writer = new FileWriter("/Users/xutingyu/Documents/Tye/TestFile/tye.txt"); writer.write(str); //清空缓冲区 writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { FileReader reader = new FileReader("/Users/xutingyu/Documents/Tye/TestFile/tye.txt"); FileWriter writer = new FileWriter("/Users/xutingyu/Documents/Tye/TestFile/tye1.txt"); char[] array = new char[10]; int length = 0; writer.write("这是复制内容:\n"); while ((length = reader.read(array)) > 0) { writer.write(new String(array, 0, length)); } writer.flush(); reader.close(); writer.close(); }
public static void main(String[] args) throws Exception { FileInputStream input = new FileInputStream("/Users/xutingyu/Documents/Tye/TestFile/tye.jpg"); FileOutputStream out = new FileOutputStream("/Users/xutingyu/Documents/Tye/TestFile/tye1.jpg"); byte[] array = new byte[1024]; int times = 0; while (input.read(array) > 0) { times++; out.write(array); if (times == 100) { break; } } out.flush(); input.close(); out.close(); System.out.println(times); }
public static void main(String[] args) throws Exception{ FileReader reader = new FileReader("/Users/xutingyu/Documents/Tye/TestFile/tye.txt"); BufferedReader br = new BufferedReader(reader); String str=""; while ((str=br.readLine())!=null) { System.out.println(str); } FileWriter writer=new FileWriter("/Users/xutingyu/Documents/Tye/TestFile/tye1.txt"); BufferedWriter bw=new BufferedWriter(writer); bw.write("dkfkjdgnjknfdlkgn"); bw.newLine(); bw.write("32422312321"); bw.flush(); bw.close(); writer.close(); }
磁盘操做:File类以抽象的方式表明文件(也能够是文件夹)svg
获取或设置文件的属性,建立,删除,查找,重命名函数
建立指针
有两个方法能够建立文件夹code
//建立 public void create() { String dirname = "/Users/xutingyu/Documents/Tye/TestFile/abc"; File f = new File(dirname); f.mkdir(); }
public void del() { String dirname = "/Users/xutingyu/Documents/Tye/TestFile/bcd/efg/hij"; File f = new File(dirname); f.delete(); }
public void delAll(File folder) { File[] files = folder.listFiles(); if (files != null) { for (File f : files) { if (f.isDirectory()) { delAll(f); } else { f.delete(); } } } folder.delete(); }
public void rename() { String path = "/Users/xutingyu/Documents/Tye/TestFile/"; String picName = "abc"; String newNmae = "bcd"; File file = new File(path + picName); if (file.renameTo(new File(path + newNmae))) { System.out.println("修改为功!"); } else { System.out.println("修改失败"); } }