There is a text file containing some text for which the following conditions are true:
> text file contains no new line, all text is in single line'
> length of text file is multiple of 4...(length%4==0)'
'
Now, how can i split the contents of text file into 4 equal parts and shuffle those parts'
For e.g. text file contains text as
"abcdefghijklmnopqrstuvwx"
'
Total length=24.........so 4 parts means 6,6,6,6
part1-abcdef
part2-ghijkl
part3-mnopqr
part4-stuvwx
'
part1,part2,part3,part4 are shuffled as part3,part1,part4,part2'
'
so i want output as
"mnopqrabcdefstuvwxghijkl"
'
I tried on this technique where the bytes from text file are to be splitted'
I am able to calculate the part1 of the original bytes...'
However, stuck on how to calculate the other 3 parts'
'
import java.io.*; public class split_contents { public static void main(String[] args) throws FileNotFoundException, IOException { File nfile=new File("D:/new_file.txt"); PrintStream out=new PrintStream(new FileOutputStream(nfile)); System.setOut(out); File file = new File("D:/old_file.txt"); { FileInputStream fin = new FileInputStream(file); int flen=(int)(file.length()); int firstpart=(flen/4); //Firstpart byte fileContent[] = new byte[firstpart]; fin.read(fileContent); String strFileContent = new String(fileContent); System.out.print(strFileContent); } } }