java - read a File and split the numbers and string / character separately -
java - read a File and split the numbers and string / character separately -
i want read file , split numbers , string / character separately in line , 1 please help out , how can in java program.
eg ; 34 indian, 45
answer :
numbers : 34, 45 string : indian
please help me out this
try next code..may help you
public static void main(string... args) { seek { file file = new file("mytext.text"); filewriter fw = new filewriter(file); bufferedwriter bw = new bufferedwriter(fw); bw.write("i 34 indian, 45"); bw.close(); filereader fr = new filereader(file); bufferedreader br = new bufferedreader(fr); string s = br.readline(); string[] info = s.split("\\d"); string[] numdata = s.split("[^0-9]"); stringbuffer numericdata = new stringbuffer(); stringbuffer chardata = new stringbuffer(); (int j = 0; j < numdata.length; j++) { numericdata.append(numdata[j]); // numericdata.append(","); } (int = 0; < data.length; i++) { chardata.append(data[i]); } system.out.println("string :" + chardata); system.out.println("numbers :" + numericdata); } grab (exception e) { // todo auto-generated grab block e.printstacktrace(); } }
java
Comments
Post a Comment