`Inline Code Example Here`
import java.io.*;
import java.util.regex.*;
String []str = {"123","0959","75443","19908","1","11879","1119","276","566777","7","675","4435","54","6588","99","124","78"};
String filename = "temp.text";
try{
File file = new File(filename);
FileWriter fw = new FileWriter(file);
for(int i=1;i<=str.lenght;i++){ // Start for
BufferedWriter bw = new BufferedWriter(fw);
bw.write(str);
bw.newLine();
} // End for
bw.close();
}catch(IOException ex){
System.out.println("Error.."+filename+" ");
}
public void Search_Digit(String str){ // Start serch
String line = "";
try{ // Start try
FileReader file = new FileReader(filename);
BufferedReader br = new BufferedReader(file);
while ((line = br.readLine()) !=null)
{ // Start while
System.out.println(line);
} // End while
br.close();
Pattern p = Pattern.compile("(\\d+){3}");
Matcher m = p.matcher(line);
while(m.find()){
System.out.println( "Found" + m.group(1));
} // End while
}catch(FileNotFoundException ex){
System.out.println("Unable to open File "+filename+"");
}
catch(IOException ex){
System.out.println("ERROR WRITING TO FILE"+ filename +"");
}
} // End search
public static void main(String[]args){
Find_digit obj = new Find_digit();
obj.Search_Digit(str);
}
}
loveparadise
0
Newbie Poster
Recommended Answers
Jump to PostAll Java code is part of a class definition - you have forgotten/lost the
class
statement that should be around line 5. Similarly the code starting a t line 10 should be inside a method definion.
Now look again at the error message that you got but decided not to …
Jump to PostLike I said before: the code starting at line 10 should be inside a method definition.
Jump to PostLet's start with the first two...
Lines 2/4 - a spelling error
Lines 6-18 - you can't just make up your own method calls for BufferedWriter like that. Look at the API doc for BufferedWriter to see what parameters you can actually pass to its write methodsI got bored …
Jump to Posthe wasn't talking about programming, rather looking at the api to see what methods you can use:
just check the api for BufferedWriter as James suggested
Jump to PostI'm not good at programming sufficiently
I guess that's why you are on a programming course! It's not easy, so it's up to you if you want to do all the necessary work.
Anyway, if you want to keep trying then start with the very first error message, …
All 20 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
loveparadise
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
loveparadise
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
stultuske
1,116
Posting Maven
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
loveparadise
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
loveparadise
0
Newbie Poster
stultuske
1,116
Posting Maven
Featured Poster
loveparadise
0
Newbie Poster
loveparadise
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
loveparadise
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.