Hi in java I am trying to split a text file [data.txt]which contains:
abc.txt
hello.jpg
play.mp4
image.jpg
text.txt
...
name of files in text form. and now i want to split this file based on file extension such as .mp3, .txt, .jpg etc using java program. because later on i want to execute that files with diffrent program based on the extention or filetype.
I have created a sample program but i am not getting how to split it based on extension
sample program:
import java.util.*;
import java.io.*;
class RF
{
public void readFile()
{
try
{
FileInputStream fstream = new FileInputStream("data.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while((strLine = br.readLine())!=null)
{
String[] splitted = strLine.split(" ");
for( String s : splitted)
{
System.out.println(s);
}
}
in.close();
} catch(Exception e)
{
}
}
}
public class FileSplit
{
public static void main(String args[])
{
RF r = new RF();
r.readFile();
}
}
I want output as :
output
abc is a text file
hello is a image file
play is a mp4 file
image is a image file
text is a text file
Thanks.