English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

3 answers

import java.util.regex.*;

String s = "This is a sentence in the code.";
Pattern p = Pattern.compile( "([a-zA-z])\\b");
Matcher m = p.matcher(s);
System.out.println( m.replaceAll("$1bry"));

2007-07-09 13:37:03 · answer #1 · answered by McFate 7 · 0 0

I did not understand your question clearly, but I will assume that you need to print "bry" word after each word in a text file:

import java.io.*;
import java.util.*;

/**
* This program reads a text file line by line and print to the console. It uses
* FileOutputStream to read the file.
*
*/
public class MyHomeWork{

public static void main(String[] args) {

File file = new File("C:\\MyHomeWork.java");
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;

try {
fis = new FileInputStream(file);

// Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

// dis.available() returns 0 if the file does not have more lines.
while (dis.available() != 0) {

// this statement reads the line from the file
String str=dis.readLine();

//this statement splits the text line into tokens (words)
StringTokenizer tokens = new StringTokenizer(str);

//this statement prints the token + " bry" as suffix
while (tokens.hasMoreTokens()) {
System.out.println(tokens.nextToken()+" bry");
}

}

// dispose all the resources after using them.
fis.close();
bis.close();
dis.close();

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Do not forget to tell me your's homework mark ;)

best regards,
Ahmed

2007-07-09 12:13:08 · answer #2 · answered by Hashim 2 · 0 0

toddler!! i'm 24 so I bear in mind the ninety's greater suitable perfect than the 80's. I enjoyed the pop way of lifestyles of my time. i actual bypass over the simplicity of being a clean newborn. I bypass over my get rid of darkness from shoes. i know Oregon direction. i replaced into in love with New youthful ones on the Block. I constantly needed to get slimed on the orange settee.

2016-11-08 20:39:48 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers