![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaHkVDna1b_plsAYmXkNsahkcflQBAHoqkW5lNIyoc8aUwam94D1Y7Y1rekLkmu79DvSnz-ky9CURYgO9bpLLa2o6mmV5Ei2QfCH-gyMU9gIabRybJJKGtK6HEroAHMsat7O-M/s200/jcaki.png)
I have changed the name of jmate to jcaki. caki, ( actually "çakı" ) means small knife in Turkish. Now version is V1.0 Alpha
String content = new SimpleFileReader("foo.txt", "utf-8").asString();Read a file as a String List
List<String> lst = new SimpleFileReader("foo.txt").asStringList();
List<String> lst = new SimpleFileReader.Builder("foo.txt")
.encoding("utf-8")
.filters(StringFilters.PASS_ONLY_TEXT)
.trim()
.build()
.asStringList();
LineIterator li = new SimpleFileReader("foo.txt").getLineIterator();
while (li.hasNext())
out.println(li.next());
IOs.closeSilently(li);
for (String s : new SimpleFileReader("foo.txt").getIterableReader())
out.println(s);
new SimpleFileWriter(tmpFile).writeString("Hello World!");
new SimpleFileWriter
.Builder("foo.txt")
.encoding("utf-8")
.keepOpen(true)
.build()
.writeLines(Collects.newArrayList("Hello", "World"));
new SimpleFileWriter("foo.txt").copyFromURL("http://google.com");
List<File> files = Files.crawlDirectory(There are more to write but it is the basic idea. neither API nor the code is stabilized. but if you are interested you can check the code. Beware.. There is shameless copying form Google collections and Apache Commons libraries.
new File("pages"),
new Files.ExtensionFilter("jsp", "tag"));
1 List<String> t = new ArrayList<String>();if we make a loop as this, and remove one element from the list,
2 t.add("Elma");
3 t.add("Armut");
4 t.add("Kiraz");
1 for (String s : t) {it throws
2 if(s.equals("Elma"))
3 t.remove(s);
4 }
1 for (Iterator<String> it = t.iterator(); it.hasNext();) {And, another way, if we do it without using the enhanced for loop, but accessing the list via indexes without using iterators:
2 if(it.next().equals("Elma"))
3 it.remove();
4 }
1 for (int i = 0; i < t.size(); i++) {this will also not throw that exception
2 if(t.get(i).equals("Elma"))
3 t.remove(t.get(i));
4 }
1 for (Iterator<String> it = t.iterator(); it.hasNext();) {
2 String s = it.next();
3 if(s.equals("Elma"))
4 t.remove(s);
5 }
1 private class Itr implements Iterator<E> {one of the member parameters of this class is called int expectedModCount, which is equivalent id modCount parameter of AbstractList. modCount is used for counting the modifications made in the list. So, when a Itr class is created, iterator will contain the current modification count parameter as the reference. If, there is a modification made in the list, such as addition, or removal, modCount will change. like ArrayList's add() method:
1 public boolean add(E e) {
2 ensureCapacity(size + 1); // Increments modCount!!
3 elementData[size++] = e;
4 return true;
5 }
1 final void checkForComodification() {metod is called, to check if there is a chance is made in the list. This throws the ConcurrentModificationException in case they do not match. This is because, Iterator's are staefull objects. They contain cursors which will be incremented by each next() call. iterator instance cannot follow the changes done by the List itself, like the list remove method, but if, the rmeove() method is called within the Iterator, since the state variables are changed accordingly it works fine. so this is the Itr's remove() method.
2 if (modCount != expectedModCount)
3 throw new ConcurrentModificationException();
4 }
1 public void remove() {
2 if (lastRet == -1)
3 throw new IllegalStateException();
4 checkForComodification();
5
6 try {
7 AbstractList.this.remove(lastRet);
8 if (lastRet < cursor)
9 cursor--;
10 lastRet = -1;
11 expectedModCount = modCount;
12 } catch (IndexOutOfBoundsException e) {
13 throw new ConcurrentModificationException();
14 }
15 }
Copyright 2009 - Java adamı All Rights Reserved. Powered by Blogger
Blogger Template by Deluxe Templates | WordPress theme by9th sphere