无需言 做自己 业 ,精于勤 荒于嬉.
- PHP杂项 批量替换文件名
-
发表日期:2022-08-05 23:32:29 | 来源: | 分类:PHP杂项
-
示例1
<?php // 效果: // [canquick影视www.canquick.com]兄弟连DVD国语配音中英字幕无水印01集.mp4 // 兄弟连01集.mp4 $handle = @opendir('./'); while ($file = readdir($handle)) { // 将 "." 及 ".." 排除不显示 if ($file != "." && $file != "..") { print_r($file); rename($file,str_replace( [ '[canquick影视www.canquick.com]', 'DVD国语配音中英字幕无水印', ], [ '', '', ], $file )); } } closedir($handle); ?>
- PHP杂项 批量修改照片文件名日期排序
-
发表日期:2022-08-05 23:15:29 | 来源: | 分类:PHP杂项
-
示例1
<?php $dir = "D:\个人收藏\照片备份 - 副本\\"; $md5 = []; $i = 0; if ($handle = opendir($dir)) { while (($file = readdir($handle)) !== false) { if (!in_array($file, ['.', '..', ['1.php']]) && !is_dir($file)) { if ($file === '1.php') continue; if (!file_exists($file)) { var_dump($file); } else { if (false) {//是否转小写文件名 rename($file, strtolower($file)); } if (true) {//程序主体 ++$i; $index = str_pad($i, 3, "0", STR_PAD_LEFT); $filectime = filectime($file); $filemtime = filemtime($file); $time = $filemtime < $filectime ? $filemtime : $filectime; $EXTENSION = pathinfo($file, PATHINFO_EXTENSION); @$exif_data = exif_read_data($file); if (!empty($exif_data['DateTime'])) { $exif_date = $exif_data['DateTime']; $fileptime = strtotime($exif_date); $time = $time < $fileptime ? $time : $fileptime; } // DateTimeDigitized if (!empty($exif_data['DateTimeOriginal'])) { $exif_date = $exif_data['DateTimeOriginal']; $fileptime = strtotime($exif_date); if ($fileptime == false) { var_dump($file . "\t" . $exif_date . "\t" . $fileptime); } else { $time = $time < $fileptime ? $time : $fileptime; } } // exit(); // $filectime = date('Y-m-d H:i:s',$filectime); // $filemtime = date('Y-m-d H:i:s',$filemtime); // $time = date('Y-m-d H:i:s',$time); // var_dump( "$file 创建时间:$filectime 修改时间:$filemtime 取时间:$time" ); // img_20150816_131130.jpg $newfile = "IMG_" . date('Ymd_His', $time) . "." . $EXTENSION; if (file_exists($newfile)) { $newfile = "IMG_" . date('Ymd_His', $time) . "_" . $index . "." . $EXTENSION; } rename($file, $newfile); // var_dump($newfile); } if (false) {//是否去重复 $file_md5 = md5_file($file); if (isset($md5[$file_md5])) { $repeat = $md5[$file_md5]; var_dump("$repeat -> $file"); $repeat_filectime = filectime($repeat); $repeat_filemtime = filemtime($repeat); $repeat_time = $repeat_filemtime < $repeat_filectime ? $repeat_filemtime : $repeat_filectime; $filectime = filectime($file); $filemtime = filemtime($file); $time = $filemtime < $filectime ? $filemtime : $filectime; if ($time <= $repeat_time) { unlink($repeat); $md5[$file_md5] = $file; } else { unlink($file); } } else { $md5[$file_md5] = $file; } } if (false) {//是否把照片归类到每天一个文件夹(事实发现同一天拍摄的照片大多是同一类) $filectime = filectime($file); $filemtime = filemtime($file); $time = $filemtime < $filectime ? $filemtime : $filectime; $_dir = date('Y-m-d', $time); @mkdir($_dir); if (!file_exists($_dir . '\\' . $file)) { copy($file, $_dir . '\\' . $file); } } } } } closedir($handle); } ?>
- JAVA基础 30.Camparable
-
发表日期:2022-08-05 16:54:10 | 来源: | 分类:JAVA基础
-
示例1
class Student implements Comparable<Student>{ private String name; private int age; private float score; public Student(String name,int age,float score){ this.name = name; this.age = age; this.score = score; } public String toString(){ return name + "\t\t" + this.age + "\t\t" + this.score; } public int compareTo(Student stu){ if(this.score>stu.score){ return -1; }else if(this.score<stu.score){ return 1; }else{ if(this.age>stu.age){ return 1; }else if(this.age<stu.age){ return -1; }else{ return 0; } } } } public class CamparableDemo01 { public static void main(String args[]) { Student stu[] = { new Student("张三",20,90.0f), new Student("李四",21,92.0f), new Student("王五",24,88.3f), new Student("赵六",19,86.1f), new Student("孙七",23,76.1f) }; for(int i=0;i<stu.length;i++){ System.out.println(stu[i]); } java.util.Arrays.sort(stu); System.out.println("<<<<<<Campare>>>>>>"); for(int i=0;i<stu.length;i++){ System.out.println(stu[i]); } } }
- JAVA基础 25.JDBC
-
发表日期:2022-08-05 16:42:10 | 来源: | 分类:JAVA基础
-
示例1
import java.sql.*; class MySql { private String sql; private ResultSet result = null; private Connection conn = null; private PreparedStatement pstmt = null; private static String MM_myDb_DRIVER = "org.gjt.mm.mysql.Driver"; private static String MM_myDb_USERNAME = "root"; private static String MM_myDb_PASSWORD = "123456"; private static String MM_myDb_STRING = "jdbc:mysql://localhost:3306/my_blog"; public ResultSet run(String sql) { try { Class.forName(MM_myDb_DRIVER); conn = DriverManager.getConnection(MM_myDb_STRING, MM_myDb_USERNAME, MM_myDb_PASSWORD); this.sql = sql; pstmt = conn.prepareStatement(sql); result = pstmt.executeQuery(); } catch (Exception e) { closeDb(); } return result; } public void closeDb() { try { result.close(); pstmt.close(); conn.close(); } catch (Exception e) { } } } public class MySqlDemo01 { public static void main(String args[]) { MySql ms = new MySql(); ResultSet result = ms.run("SELECT id,title FROM content"); try { while (result.next()) { System.out.println("编号:" + result.getString(1) + "----------------" + "标题:" + result.getString(2) + "<br/>"); } } catch (Exception e) { } finally { ms.closeDb(); } } }
- JAVA基础 29.Serializable
-
发表日期:2022-08-05 16:41:10 | 来源: | 分类:JAVA基础
-
示例1
import java.io.Externalizable; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; public class Pet implements Externalizable{ private static final long serialVersionUID = 1L; private String name ; private int age ; private String sex ; public Pet(){} public Pet(String name , int age , String sex){ setName(name); setAge(age); setSex(sex); } public String toString() { return "姓名:"+name+" 年龄:"+age+" 性别:"+sex; } @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { // TODO Auto-generated method stub setName((String) in.readObject()); setAge(in.readInt()); //setSex((String) in.readObject()); Sex就不会被保存 } @Override public void writeExternal(ObjectOutput out) throws IOException { // TODO Auto-generated method stub out.writeObject(getName()); out.writeInt(getAge()); //out.writeObject(getSex()); } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } public void setSex(String sex) { this.sex = sex; } public String getSex() { return sex; } }
示例2
import java.io.Serializable; public class Person implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String name ; private int age ; private transient String sex ;//transient 声明的变量不会被序列号 public Person(String name, int age , String sex) { // TODO Auto-generated constructor stub setName(name); setAge(age); setSex(sex); } public String toString() { return "姓名:"+name+" 年龄:"+age+" 性别:"+sex; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } public void setSex(String sex) { this.sex = sex; } public String getSex() { return sex; } }
示例3
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; public class ObjectOutputStreamDemo { /** * @param args * @throws IOException * @throws ClassNotFoundException */ public static void main(String[] args) throws IOException, ClassNotFoundException { // TODO Auto-generated method stub File file = new File("D:" + File.separator + "javademo.txt"); OutputStream out = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(out); oos.writeObject(new Person("张三", 22, "男"));//性别不会被保存 transient 声明的变量不会被序列号 InputStream in = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(in); Person person = (Person) ois.readObject(); System.out.println(person.getName()); System.out.println(person.getAge()); System.out.println(person); } }
示例4
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; public class ObjectOutputStreamDemo2 { /** * @param args * @throws IOException * @throws ClassNotFoundException */ public static void main(String[] args) throws IOException, ClassNotFoundException { // TODO Auto-generated method stub File file = new File("D:"+File.separator+"javademo.txt"); OutputStream out = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(out ); oos.writeObject(new Pet("小白",3,"公"));//性别不会被保存 没有配置writeExternal / readExternal InputStream in = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(in); Pet pet = (Pet) ois.readObject(); System.out.println(pet.getName()); System.out.println(pet.getAge()); System.out.println(pet); } }
- JAVA基础 28.Interface
-
发表日期:2022-08-05 16:38:14 | 来源: | 分类:JAVA基础
-
示例1
interface A{ //接口中的方法不能被实现,或者说必须全部是抽象方法 //接口不能实现接口,而是继承父接口 //实现接口的类,必须复写并实现接口的全部方法。除非是抽象类且是抽象方法。 public abstract void print(); public void printr(); public void printf(); } interface B extends A{ public void print(String str); public void prinv(String str); } class C implements B{ @Override public void print(String str) { // TODO Auto-generated method stub } @Override public void print() { } @Override public void printf() { // TODO Auto-generated method stub } @Override public void printr() { // TODO Auto-generated method stub } @Override public void prinv(String str) { // TODO Auto-generated method stub } } public class InterfaceDemo01 { public static void main(String[] args) { } }
- JAVA基础 27.Abstract
-
发表日期:2022-08-05 16:37:28 | 来源: | 分类:JAVA基础
-
示例1
abstract class A{ //1.抽象类中可以没有抽象方法(无意义,但是抽象方法必须没有方法体 //2.抽象类中可以有(非抽象方法)被实现的方法即有方法体 //3.抽象类中的所有抽象方法必须要被继承的 【非抽象子类】复写并实现,如果是抽象的子类则无需 //4.抽象类不能被直接实例化 public abstract void print(String str); public abstract void printf(String str); public void printr(String str){ System.out.println(str); } } abstract class B extends A{ @Override public void print(String str) { // TODO Auto-generated method stub System.out.println(str); } } class C extends B{ @Override public void printf(String str) { // TODO Auto-generated method stub System.out.println(str); } } public class AbstractDemo01 { public static void main(String[] args) { A a = new C(); a.printr("printr"); a.print("print"); a.printf("printf"); } }
- JAVA基础 26.Iterator
-
发表日期:2022-08-05 16:36:39 | 来源: | 分类:JAVA基础
-
示例1
import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class IteratorDemo { public static void main(String[] args) { // TODO 自动生成的方法存根 List<String> list = new ArrayList<String>(); list.add("hello"); list.add(","); list.add("world"); Iterator<String> iterator = list.iterator(); while (iterator.hasNext()) { System.out.print(iterator.next()); } } }
- JAVA基础 24.Collection
-
发表日期:2022-08-05 16:35:35 | 来源: | 分类:JAVA基础
-
示例1
import java.util.ArrayList; import java.util.Collection; import java.util.List; public class ListDemo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Collection<String> collection = new ArrayList<String>(); collection.add("eniac"); collection.add("bast man!"); List<String> list = new ArrayList<String>(); list.add("hello"); list.add("world"); list.add(1,"-"); list.addAll(0,collection); System.out.println(list);//[eniac, bast man!, hello, -, world] list.remove(3); System.out.println(list);//[eniac, bast man!, hello, world] for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i)); } System.out.println(); System.out.println(list.toArray());//[Ljava.lang.Object;@c17164 System.out.println(list.toArray(new String[]{}));//[Ljava.lang.String;@de6ced } }
- JAVA基础 23.Enumeration
-
发表日期:2022-08-05 16:34:47 | 来源: | 分类:JAVA基础
-
示例1
import java.util.Enumeration; import java.util.Vector; public class EnumDemo01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Vector<String> all = new Vector<String>(); all.add("Hello "); all.add("world "); all.add("!"); Enumeration<String> enumeration = all.elements(); while (enumeration.hasMoreElements()) { String string = (String) enumeration.nextElement(); System.out.print(string); } System.out.println(""); //foreach 用PHP的习惯去解释 for(TYPE $val : $arr){} for (String string : all) { System.out.print(string); } } }
- JAVA基础 22.Properties
-
发表日期:2022-08-05 16:34:13 | 来源: | 分类:JAVA基础
-
示例1
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Properties; public class PropertiesDemo01 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("D:"+File.separator+"javaDemo.txt"); Properties pro = new Properties(); pro.setProperty("name", "张三"); pro.setProperty("age", "22"); pro.setProperty("sex", "男"); System.out.println(pro.getProperty("name")); System.out.println(pro.getProperty("age")); System.out.println(pro.getProperty("sex")); //#保存至文件 OutputStream out = new FileOutputStream(file); //pro.save(out , "这里是注释");//save方法过时了 //pro.store(out, "这里是注释"); //pro.storeToXML(out, "这里是注释", "GBK"); pro.storeToXML(out, "这里是注释");//encoding 默认是UTF-8 //#从文件中读取 InputStream in = new FileInputStream(file); pro.loadFromXML(in); System.out.println(pro.getProperty("name")); System.out.println(pro.getProperty("age")); System.out.println(pro.getProperty("sex")); } }
- JAVA基础 21.Map
-
发表日期:2022-08-05 16:33:10 | 来源: | 分类:JAVA基础
-
示例1
import java.util.HashMap; import java.util.Map; public class MapDemo01 { public static void main(String[] args) { // TODO 自动生成的方法存根 Map<String, String> map = new HashMap<String, String>(); map.put("name", "zhangsan"); map.put("work", "techer"); } }
示例2
import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class HashMapDemo01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub HashMap<String, String> map = new HashMap<String, String>();//HashMap => TreeMap = sort map.put("百度", "www.baidu.com"); map.put("腾讯", "www.qq.com"); map.put("网易", "www.163.com"); if (map.containsKey("百度")) { System.out.println(map.get("百度")); } Set<String> keys = map.keySet();//Collection<String> keys = map.values(); Iterator<String> iterator = keys.iterator(); while (iterator.hasNext()) { String str = iterator.next(); System.out.print(str+"\\"); } } }
- JAVA基础 20.List
-
发表日期:2022-08-05 16:31:29 | 来源: | 分类:JAVA基础
-
示例1
import java.util.ArrayList; import java.util.Collection; import java.util.List; public class ArrayListDemo01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub List<String> allList = new ArrayList<String>(); allList.add("hello"); allList.add("world"); allList.add(1,"my");//在第二个位置上添加内容 System.out.println(allList); Collection<String> allCollection = new ArrayList<String>(); allCollection.add("hello"); allCollection.add("world"); //allCollection.add(1," ");//错误i System.out.println(allCollection); allList.addAll(allCollection);//可以指定位置 System.out.println(allList); allList.remove("world");//根据内容删除 但是只删除第一个 System.out.println(allList); allList.remove(0);//根据内容删除 但是只删除第一个 System.out.println(allList); System.out.println("allList的长度为:"+allList.size()); for (int i = 0; i < allList.size(); i++) { System.out.print(allList.get(i)+"、"); } String arr[] = allList.toArray(new String[]{});//将list 对象转换为 array 对象 } }
示例2
import java.util.Set; import java.util.TreeSet; class Person implements Comparable<Person> { private int age; private String name; public Person(String name, int age) { setName(name); setAge(age); } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int compareTo(Person person) { if (this.age > person.age) { return 1; } else if (this.age < person.age) { return -1; } else { //return 0; return this.name.compareTo(person.name); } } public String toString() { return "姓名:" + getName() + " 年龄:" + getAge(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if (age != other.age) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } } public class TreeSetDemo { public static void main(String[] args) { // TODO 自动生成的方法存根 Set<Person> treeSet = new TreeSet<Person>(); treeSet.add(new Person("张三", 30)); treeSet.add(new Person("李四", 40)); treeSet.add(new Person("王二", 20)); treeSet.add(new Person("赵六", 60)); treeSet.add(new Person("麻子", 30)); treeSet.add(new Person("李四", 13)); treeSet.add(new Person("赵六", 60)); System.out.println(treeSet); //return 0; //[姓名:李四 年龄:13, 姓名:王二 年龄:20, 姓名:张三 年龄:30, 姓名:李四 年龄:40, 姓名:赵六 年龄:60] /** * 麻子 30 不见了 * 李四 13、40 * 赵六去重复了 */ //[姓名:李四 年龄:13, 姓名:王二 年龄:20, 姓名:张三 年龄:30, 姓名:麻子 年龄:30, 姓名:李四 年龄:40, 姓名:赵六 年龄:60] //赵六去重复了只有赵六去重复了 //[姓名:李四 年龄:13, 姓名:王二 年龄:20, 姓名:张三 年龄:30, 姓名:麻子 年龄:30, 姓名:李四 年龄:40, 姓名:赵六 年龄:60] } }
- JAVA基础 19.Charset
-
发表日期:2022-08-05 16:24:36 | 来源: | 分类:JAVA基础
-
示例1
public class CharsetDemo01 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(System.getProperty("file.encoding"));//GBK } }
- JAVA基础 18.zip
-
发表日期:2022-08-05 16:22:18 | 来源: | 分类:JAVA基础
-
示例1
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZipDemo01 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("d:"+File.separator+"test.txt"); File zipFile = new File("d:"+File.separator+"test.zip"); FileInputStream fis = new FileInputStream(file); FileOutputStream fos = new FileOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(fos); zos.setComment("这里是注释"); ZipEntry zEntry = new ZipEntry(file.getName()); zos.putNextEntry(zEntry); int temp = 0; while ((temp=fis.read())!=-1) { zos.write(temp); } zos.finish() ; zos.close(); } private static Object Charset(String string) { // TODO Auto-generated method stub return null; } }
示例2
/** * Created by Administrator on 2016/4/5. */ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; public class ZipUtils { public static void zip(ArrayList<String> src, String dest) throws IOException { ZipOutputStream out = null; try { File outFile = new File(dest);// 源文件或者目录 out = new ZipOutputStream(new FileOutputStream(outFile)); for (int i = 0; i < src.size(); i++) { File fileOrDirectory = new File(src.get(i));// 压缩文件路径 zipFileOrDirectory(out, fileOrDirectory, ""); } } catch (IOException ex) { ex.printStackTrace(); } finally { // 关闭输出流 if (out != null) { try { out.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } public static void zip(String src, String dest) throws IOException { // 提供了一个数据项压缩成一个ZIP归档输出流 ZipOutputStream out = null; try { File outFile = new File(dest);// 源文件或者目录 File fileOrDirectory = new File(src);// 压缩文件路径 out = new ZipOutputStream(new FileOutputStream(outFile)); // 如果此文件是一个文件,否则为false。 if (fileOrDirectory.isFile()) { zipFileOrDirectory(out, fileOrDirectory, ""); } else {// 返回一个文件或空阵列。 File[] entries = fileOrDirectory.listFiles(); for (int i = 0; i < entries.length; i++) { // 递归压缩,更新curPaths zipFileOrDirectory(out, entries[i], ""); } } } catch (IOException ex) { ex.printStackTrace(); } finally { // 关闭输出流 if (out != null) { try { out.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } private static void zipFileOrDirectory(ZipOutputStream out, File fileOrDirectory, String curPath) throws IOException { // 从文件中读取字节的输入流 FileInputStream in = null; try { // 如果此文件是一个目录,否则返回false。 if (!fileOrDirectory.isDirectory()) { // 压缩文件 byte[] buffer = new byte[4096]; int bytes_read; in = new FileInputStream(fileOrDirectory); // 实例代表一个条目内的ZIP归档 ZipEntry entry = new ZipEntry(curPath + fileOrDirectory.getName()); // 条目的信息写入底层流 out.putNextEntry(entry); while ((bytes_read = in.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } out.closeEntry(); } else { // 压缩目录 File[] entries = fileOrDirectory.listFiles(); for (int i = 0; i < entries.length; i++) { // 递归压缩,更新curPaths zipFileOrDirectory(out, entries[i], curPath + fileOrDirectory.getName() + "/"); } } } catch (IOException ex) { ex.printStackTrace(); // throw ex; } finally { if (in != null) { try { in.close(); } catch (IOException ex) { ex.printStackTrace(); } } } } @SuppressWarnings("unchecked") public static void unzip(String zipFileName, String outputDirectory) throws IOException { ZipFile zipFile = null; try { zipFile = new ZipFile(zipFileName); Enumeration e = zipFile.entries(); ZipEntry zipEntry = null; File dest = new File(outputDirectory); dest.mkdirs(); while (e.hasMoreElements()) { zipEntry = (ZipEntry) e.nextElement(); String entryName = zipEntry.getName(); InputStream in = null; FileOutputStream out = null; try { if (zipEntry.isDirectory()) { String name = zipEntry.getName(); name = name.substring(0, name.length() - 1); File f = new File(outputDirectory + File.separator + name); f.mkdirs(); } else { int index = entryName.lastIndexOf("\\"); if (index != -1) { File df = new File(outputDirectory + File.separator + entryName.substring(0, index)); df.mkdirs(); } index = entryName.lastIndexOf("/"); if (index != -1) { File df = new File(outputDirectory + File.separator + entryName.substring(0, index)); df.mkdirs(); } File f = new File(outputDirectory + File.separator + zipEntry.getName()); // f.createNewFile(); in = zipFile.getInputStream(zipEntry); out = new FileOutputStream(f); int c; byte[] by = new byte[1024]; while ((c = in.read(by)) != -1) { out.write(by, 0, c); } out.flush(); } } catch (IOException ex) { ex.printStackTrace(); throw new IOException("解压失败:" + ex.toString()); } finally { if (in != null) { try { in.close(); } catch (IOException ex) { } } if (out != null) { try { out.close(); } catch (IOException ex) { } } } } } catch (IOException ex) { ex.printStackTrace(); throw new IOException("解压失败:" + ex.toString()); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ex) { } } } } } /* * Activity调用 package com.comc; import java.io.IOException; import * com.zipUtil.ZipUtil; import android.app.Activity; import android.os.Bundle; * public class IZipActivity extends Activity { * * * @Override public void onCreate(Bundle savedInstanceState) { * super.onCreate(savedInstanceState); setContentView(R.layout.main); try { * ZipUtil.zip("/data/data/com.comc/databases", * "/data/data/com.comc/databases.zip"); * ZipUtil.unzip("/data/data/com.comc/databases.zip", * "/data/data/com.comc/databases"); } catch (IOException e) { * e.printStackTrace(); } } * * } */
示例3
import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Demo { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<String> fileListsList = new ArrayList<String>(); fileListsList.add("D:/zip/device-2016-03-26-195134.png"); fileListsList.add("D:/demo/hyasset/config.xml"); fileListsList.add("D:/demo.txt"); fileListsList.add("D:/demosvn/YCCitizen/build/intermediates/dex-cache/"); try { ZipUtils.zip(fileListsList, "D:/ziped/abc.zip"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* try { ZipUtils.zip("D:/zip/", "D:/ziped/abc.zip"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } }
- JAVA基础 15.DataOutputStream
-
发表日期:2022-08-05 16:20:31 | 来源: | 分类:JAVA基础
-
示例1
import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class OutputDemo01 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("d:"+File.separator+"test.txt"); FileOutputStream os = new FileOutputStream(file); DataOutputStream dos = new DataOutputStream(os); int arg = 123; dos.writeInt(arg); } }
- JAVA基础 14.Scanner
-
发表日期:2022-08-05 16:19:27 | 来源: | 分类:JAVA基础
-
示例1
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ScannerDemo01 { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub File file = new File("d:"+File.separator+"test.txt"); Scanner scanner = new Scanner(file); /* String string = scanner.next(); System.out.println(string); */ while (scanner.hasNext()) { String string = (String) scanner.next(); System.out.println(string); } } }
- JAVA基础 13.BufferedReader
-
发表日期:2022-08-05 16:17:46 | 来源: | 分类:JAVA基础
-
示例1
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class ReaderDemo01 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("d:" + File.separator + "OutputStreamDemo.txt"); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String str = null; while ((str = br.readLine()) != null) { System.out.println(str); } fr.close(); br.close(); /* FileReader fReader = null; try { fReader = new FileReader(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } BufferedReader bReader = new BufferedReader(fReader); try { System.out.print(bReader.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } }
示例2
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; public class ReaderDemo02 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub InputStream is = System.in;//字节流 InputStreamReader isr = new InputStreamReader(is);//转换为字符流 BufferedReader br = new BufferedReader(isr); System.out.println("请输入内容"); String str = null; while ((str = br.readLine())!=null) { if ("exit".equals(str)) { break; } System.out.println(str); } is.close(); isr.close(); br.close(); System.out.println("bye!"); /* BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); String string = null; System.out.println("请输入内容"); try { string = bReader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("输入内容:"+string); */ } }
示例3
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class ExecDemo01 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int i = 0 ; int j = 0 ; BufferedReader bReader = new BufferedReader(new InputStreamReader(System.in)); String string = null; System.out.println("请输入第一个数字:"); string = bReader.readLine(); i = Integer.parseInt(string); System.out.println("请输入第二个数字:"); string = bReader.readLine(); j = Integer.parseInt(string); System.out.println(i+"+"+j+"="+(i+j)); } }
- JAVA基础 12.InputStreamReader和OutputStreamWriter
-
发表日期:2022-08-05 16:13:02 | 来源: | 分类:JAVA基础
-
示例1
package stream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class InputStreamReaderDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("D:"+File.separator+"123.txt"); FileInputStream stream = new FileInputStream(file); InputStreamReader reader = new InputStreamReader(stream); char c[] = new char[1024]; int length = reader.read(c); System.out.println(new String(c,0,length)); stream.close(); reader.close(); } }
示例2
package stream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; public class OutputStreamWriterDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("D:"+File.separator+"123.txt"); FileOutputStream stream = new FileOutputStream(file); OutputStreamWriter writer = new OutputStreamWriter(stream); writer.write("测试一下3。"); writer.close(); stream.close(); } }
- JAVA基础 10.RandomAccessFile
-
发表日期:2022-08-05 16:09:05 | 来源: | 分类:JAVA基础
-
示例1
package File; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.RandomAccessFile; public class RandomAccessFileDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File file = new File("D:" + File.separator + "RandomAccessFile.txt"); //两种写法均可 //RandomAccessFile rFile = new RandomAccessFile("D:"+File.separator+"test.txt", "rw"); RandomAccessFile rFile = new RandomAccessFile(file, "rw"); String string = "abcdefg我去这是什么情况?"; ; rFile.write(string.getBytes());//写入中文会乱码 rFile.close(); write(); read(); } private static void read() { // TODO Auto-generated method stub File file = new File("d:" + File.separator + "123.txt"); RandomAccessFile rFile = null; try { rFile = new RandomAccessFile(file, "r"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { byte c[] = new byte[(int) rFile.length()]; rFile.read(c); System.out.println(new String(c)); } catch (IOException e) { e.printStackTrace(); } } public static void write() { File file = new File("d:" + File.separator + "123.txt"); RandomAccessFile rFile = null; try { rFile = new RandomAccessFile(file, "rw"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String name = "zhangsan"; int age = 30; try { rFile.writeInt(age); // rFile.writeBytes(name); rFile.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
- 前端开发(1)
- 数据库(0)
- PHP(0)
- PHP杂项(34)
- PHP基础-李炎恢系列课程(20)
- 中文函数手册(0)
- 错误处理 函数(13)
- OPcache 函数(6)
- PHP 选项/信息 函数(54)
- Zip 函数(10)
- Hash 函数(15)
- OpenSSL 函数(63)
- Date/Time 函数(51)
- 目录函数(9)
- Fileinfo 函数(6)
- iconv 函数(11)
- 文件系统函数(81)
- 多字节字符串 函数(57)
- GD 和图像处理 函数(114)
- 可交换图像信息(5)
- Math 函数(50)
- 程序执行函数(11)
- PCNTL 函数(23)
- JSON 函数(4)
- SPL 函数(15)
- URL 函数(10)
- cURL 函数(32)
- 网络 函数(33)
- FTP 函数(36)
- Session 函数(23)
- PCRE 函数(11)
- PCRE 正则语法(19)
- 数组 函数(81)
- 类/对象 函数(18)
- 函数处理 函数(13)
- 变量处理 函数(37)
- SimpleXML 函数(3)
- 杂项 函数(31)
- 字符串 函数(101)
- JAVA(0)
- Android(0)
- Linux(0)
- 其他(0)