Created
December 8, 2010 01:58
-
-
Save nobeans/732782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Diamond6 { | |
public static void main(String[] args) { | |
List<String> grandchild1 = Arrays.asList("A-1", "A-2", "A-3"); | |
List<String> grandchild2 = Arrays.asList("B-1", "B-2", "B-3"); | |
List<String> grandchild3 = Arrays.asList("C-1", "C-2", "C-3"); | |
Map<Integer, List<String>> child1 = new HashMap<Integer, List<String>>(); | |
child1.put(1, grandchild1); | |
child1.put(2, grandchild2); | |
Map<Integer, List<String>> child2 = new HashMap<Integer, List<String>>(); | |
child2.put(3, grandchild3); | |
Map<String, Map<Integer, List<String>>> data = new HashMap<String, Map<Integer, List<String>>>(); | |
data.put("Child1", child1); | |
data.put("Child2", child2); | |
System.out.println(data); | |
} | |
} | |
import java.util.*; | |
class Diamond7 { | |
public static void main(String[] args) { | |
List<String> grandchild1 = Arrays.asList("A-1", "A-2", "A-3"); | |
List<String> grandchild2 = Arrays.asList("B-1", "B-2", "B-3"); | |
List<String> grandchild3 = Arrays.asList("C-1", "C-2", "C-3"); | |
Map<Integer, List<String>> child1 = new HashMap<>(); | |
child1.put(1, grandchild1); | |
child1.put(2, grandchild2); | |
Map<Integer, List<String>> child2 = new HashMap<>(); | |
child2.put(3, grandchild3); | |
Map<String, Map<Integer, List<String>>> data = new HashMap<>(); | |
data.put("Child1", child1); | |
data.put("Child2", child2); | |
System.out.println(data); | |
} | |
} | |
import java.io.*; | |
class FileCopy6 { | |
public static void main(String[] args) throws Exception { | |
BufferedInputStream is = null; | |
BufferedOutputStream os = null; | |
try { | |
is = new BufferedInputStream( new FileInputStream(new File("/tmp/hoge"))); | |
os = new BufferedOutputStream(new FileOutputStream(new File("/tmp/foo"))); | |
int length = 0; | |
byte[] buffer = new byte[1024]; | |
while ((length = is.read(buffer)) >= 0) { | |
System.out.write(buffer, 0, length); | |
os.write(buffer, 0, length); | |
} | |
} finally { | |
try { if (is != null) is.close(); } catch (IOException e) { /* ignored */ } | |
try { if (os != null) os.close(); } catch (IOException e) { /* ignored */ } | |
} | |
System.out.println("Done."); | |
} | |
} | |
import java.io.*; | |
class FileCopy7 { | |
public static void main(String[] args) throws Exception { | |
try (BufferedInputStream is = new BufferedInputStream( new FileInputStream(new File("/tmp/hoge"))); | |
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File("/tmp/foo")))) { | |
int length = 0; | |
byte[] buffer = new byte[1024]; | |
while ((length = is.read(buffer)) >= 0) { | |
System.out.write(buffer, 0, length); | |
os.write(buffer, 0, length); | |
} | |
} | |
System.out.println("Done."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment