Good night
My fiend asked me a question in java
she want to read an article from text file (for example eadokingInputFile.txt )
then manipulate it (read all word in each line an index it )
put each word with the line number and output them to text file (for example eadokingOutputFile.txt)
input examples :
Eadoking Blog
By Ead AlDoukanje
email1 eadoking@yahoo.com
email1 info@eadoking.com
mob +9363-932728084http://eadoking.com
output example :
Eadoking , 1
Blog , 1
By , 2
Ead , 2
AlDoukanje , 2
email1 , 3
eadoking@yahoo.com , 3
email1 , 4
info@eadoking.com , 4
mob , 5
+9363-932728084 , 5
http://eadoking.com , 6
now the code. any question just post it in comment
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
/**
*
* @author Eadoking
* @website http://eadoking.com
* @email eadoking@yahoo.com
* @email info@eadoking.com
* @mobile +963 932728084
*/
public class eadoking_com_Index_Test {
static public String eadokingReadFile(File inputFile) {
StringBuilder indexedContents = new StringBuilder();
try {
BufferedReader input = new BufferedReader(new FileReader(inputFile));
try {
String line = null;
int lineCounter = 0;
while ((line = input.readLine()) != null) {
lineCounter++;
String token[] = line.split(" ");
for (String s : token) {
indexedContents.append(s + " , " + lineCounter);
indexedContents.append(System.getProperty("line.separator"));
}
}
} finally {
input.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
return indexedContents.toString();
}
static public void eadokingWriteIndexed(File outputFile, String indexedContent) throws FileNotFoundException, IOException {
if (outputFile == null) {
throw new IllegalArgumentException("File should not be null.");
}
Writer output = new BufferedWriter(new FileWriter(outputFile));
try {
// create file if not exists
if (!outputFile.exists()) {
outputFile.createNewFile();
}
output.write(indexedContent);
} finally {
output.close();
}
}
public static void main(String[] args) throws FileNotFoundException, IOException {
String inF = null;
String ouF = null;
if (args.length != 0) {
inF = args[0];
ouF = args[1];
} else {
inF = "d:\\eadoknigInputFile.txt";
ouF = "d:\\eadoknigOutputFile.txt";
}
// read an index the file
String indexedContent = eadokingReadFile(new File(inF));
// write the indexed file
eadokingWriteIndexed(new File(ouF), indexedContent);
System.out.println("All Done OK");
System.out.println("By Eadoking Blog\nhttp://eadoking.com");
}
}





انا ما كتير فهمت القصد بس شوف هيك اذا بيمشي
هلا الباث لازم يكون من عدة اشكال وابسط شي هوي كما يلي
c:\test\file.ext
وهون قصدنا الملف file.ext
ألموجود في الفولدر test
على السواقة c
ولنحط المسا للملف لازم نكتب
String path = “c:\\test\\file.ext”
وهون حطينا \\
لانو اول \ هيي عبارة عن مفتاح هروب
وال \ التانية هيي عبارة عن تبع المسار
يعني انو الرمز \ التاني اعتبروا محرف عادي مو محرف خاص
بكفي الشرح هيك اخوي ولا بدك اكتر بس ياريت توضح تماما شو بتريد من السؤال او شو بتريد مني اشرحلك
انا ما كتير فهمت القصد بس شوف هيك اذا بيمشي
هلا الباث لازم يكون من عدة اشكال وابسط شي هوي كما يلي
c:testfile.ext
وهون قصدنا الملف file.ext
ألموجود في الفولدر test
على السواقة c
ولنحط المسا للملف لازم نكتب
String path = “c:\test\file.ext”
وهون حطينا \
لانو اول هيي عبارة عن مفتاح هروب
وال التانية هيي عبارة عن تبع المسار
يعني انو الرمز التاني اعتبروا محرف عادي مو محرف خاص
بكفي الشرح هيك اخوي ولا بدك اكتر بس ياريت توضح تماما شو بتريد من السؤال او شو بتريد مني اشرحلك
بليززززز لو سمحت أبغى شرح للباث اللي في الفايل ؟؟
dierct bath
بليززززز لو سمحت أبغى شرح للباث اللي في الفايل ؟؟
dierct bath
I want to quote your post in my blog. It can?
And you et an account on Twitter?
I want to quote your post in my blog. It can?
And you et an account on Twitter?
Ok,
You can put the things that you didn’t understand then i’ll explain
Ok,
You can put the things that you didn’t understand then i’ll explain
THANK YOU SO MUCH EADOOO
IT IS A BIT HARD FOR ME THOUGH.. U NEED TO EXPLAIN SOME STUFF!!
SOME WORDS I DIDN’T HEAR OF BEFORE.. I HOPE THAT IS NORMAL!!
THANK U SO MUCH UR THE BEST
THANK YOU SO MUCH EADOOO
IT IS A BIT HARD FOR ME THOUGH.. U NEED TO EXPLAIN SOME STUFF!!
SOME WORDS I DIDN’T HEAR OF BEFORE.. I HOPE THAT IS NORMAL!!
THANK U SO MUCH UR THE BEST
اي سؤال انا جاهز
بس حطو بالتعليقات شو السؤال وتكرموا
اي سؤال انا جاهز
بس حطو بالتعليقات شو السؤال وتكرموا