-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.db.letdb.file; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @created: 2011-11-16 | ||
* @author : jias chao<[email protected]> | ||
*/ | ||
public class InWrite { | ||
|
||
private String path = ""; | ||
private String fileName=""; | ||
private BufferedReader read; | ||
private BufferedWriter write; | ||
|
||
public static int indexOfLine = 0; | ||
|
||
public InWrite(String _fileName) throws IOException{ | ||
this.fileName = _fileName; | ||
openFile(); | ||
} | ||
|
||
public void openFile() throws IOException{ | ||
File file = new File(this.fileName); | ||
if (!file.exists()){ | ||
file.createNewFile(); | ||
} | ||
FileReader fr = new FileReader(file); | ||
FileWriter fw = new FileWriter(file,true); | ||
read = new BufferedReader(fr); | ||
write = new BufferedWriter(fw); | ||
} | ||
|
||
public void write(String context) throws IOException{ | ||
write.write(context); | ||
write.newLine(); | ||
write.flush(); | ||
} | ||
|
||
public String readNextLine() throws IOException{ | ||
read.skip(indexOfLine); | ||
indexOfLine = indexOfLine + 5; | ||
return read.readLine(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.db.letdb.file; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* @created: 2011-11-16 | ||
* @author : jias chao<[email protected]> | ||
*/ | ||
public class TestInWrite { | ||
|
||
@Test | ||
public void test() { | ||
fail("Not yet implemented"); | ||
} | ||
|
||
@Test | ||
public void testWrite() throws IOException{ | ||
InWrite iw = new InWrite("context.txt"); | ||
iw.write("abc"); | ||
iw.write("123"); | ||
|
||
} | ||
|
||
@Test | ||
public void testRead() throws IOException{ | ||
InWrite iw = new InWrite("context.txt"); | ||
String str = iw.readNextLine(); | ||
System.out.print(str); | ||
|
||
} | ||
|
||
} |