Click here to Skip to main content
15,911,711 members
Home / Discussions / Java
   

Java

 
GeneralRe: Array Subsequence Pin
Nagy Vilmos9-Oct-09 3:52
professionalNagy Vilmos9-Oct-09 3:52 
QuestionJava Intenet Jobs.... Pin
TGeist8-Oct-09 18:33
TGeist8-Oct-09 18:33 
AnswerRe: Java Intenet Jobs.... Pin
Richard MacCutchan8-Oct-09 22:49
mveRichard MacCutchan8-Oct-09 22:49 
AnswerRe: Java Intenet Jobs.... Pin
42774809-Oct-09 3:12
42774809-Oct-09 3:12 
GeneralRe: Java Intenet Jobs.... Pin
Richard MacCutchan9-Oct-09 4:31
mveRichard MacCutchan9-Oct-09 4:31 
GeneralRe: Java Intenet Jobs.... Pin
42774809-Oct-09 6:29
42774809-Oct-09 6:29 
QuestionParsing Text Files and Spliting on '>' Pin
meixiang68-Oct-09 14:09
meixiang68-Oct-09 14:09 
AnswerRe: Parsing Text Files and Spliting on '>' Pin
42774809-Oct-09 3:13
42774809-Oct-09 3:13 
I took it one step further.

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

public class SplitFiles {
	public static void main(String[] args) throws Exception {
		File mainfile = new File("MainFile.txt");

		Scanner scan = new Scanner(mainfile);

		ArrayList<String> List = new ArrayList<String>();

		String getFileName = "";

		while (scan.hasNext()) {
			List.add(scan.nextLine());
		}

		for (int i = 0; i < List.size(); i++) {
			if (List.get(i).charAt(0) == '>') {

				getFileName = List.get(i).replace(">", "");

				String result = "";

				for (int j = 0; j < getFileName.length(); j++) {
					if (getFileName.charAt(j) == ' ') {
						result = getFileName.substring(0, j);
						break;
					}
				}

				File output;

				if (new File(result + ".txt").exists()) {
					BufferedWriter out = new BufferedWriter(new FileWriter(
							result + ".txt", true));

					out.write(List.get(i) + "\n");

					int k;

					for (k = i + 1; k < List.size(); k++) {
						if (List.get(k).charAt(0) == '>')
							break;
						else {
							out.write(List.get(k) + "\n");
						}
					}

					out.close();
				} else {
					output = new File(result + ".txt");

					PrintWriter out = new PrintWriter(output);

					out.println(List.get(i));

					int k;

					for (k = i + 1; k < List.size(); k++) {
						if (List.get(k).charAt(0) == '>')
							break;
						else {
							out.println(List.get(k));
						}
					}

					out.close();
				}
			}
		}
	}
}


Good Luck
GeneralRe: Parsing Text Files and Spliting on '&gt;' Pin
meixiang69-Oct-09 4:22
meixiang69-Oct-09 4:22 
GeneralRe: Parsing Text Files and Spliting on '&gt;' Pin
42774809-Oct-09 6:20
42774809-Oct-09 6:20 
GeneralRe: Parsing Text Files and Spliting on '&gt;' Pin
meixiang69-Oct-09 8:56
meixiang69-Oct-09 8:56 
GeneralRe: Parsing Text Files and Spliting on '&gt;' Pin
42774809-Oct-09 9:42
42774809-Oct-09 9:42 
GeneralRe: Parsing Text Files and Spliting on '&gt;' Pin
meixiang69-Oct-09 9:56
meixiang69-Oct-09 9:56 
Question12 days of christmas Pin
Shah Ravi8-Oct-09 9:05
Shah Ravi8-Oct-09 9:05 
AnswerRe: 12 days of christmas Pin
Wes Aday8-Oct-09 9:51
professionalWes Aday8-Oct-09 9:51 
GeneralRe: 12 days of christmas Pin
Shah Ravi8-Oct-09 10:19
Shah Ravi8-Oct-09 10:19 
GeneralRe: 12 days of christmas Pin
David Skelly8-Oct-09 22:13
David Skelly8-Oct-09 22:13 
AnswerRe: 12 days of christmas Pin
42774809-Oct-09 3:16
42774809-Oct-09 3:16 
QuestionJ2METext Field Problem Pin
DarkSorrow388-Oct-09 4:56
DarkSorrow388-Oct-09 4:56 
AnswerRe: J2METext Field Problem Pin
42774809-Oct-09 3:20
42774809-Oct-09 3:20 
QuestionEpub-LRFTools [modified] Pin
sharkbc7-Oct-09 21:54
sharkbc7-Oct-09 21:54 
AnswerRe: Epub-LRFTools Pin
Nagy Vilmos7-Oct-09 22:04
professionalNagy Vilmos7-Oct-09 22:04 
GeneralRe: Epub-LRFTools Pin
sharkbc7-Oct-09 23:30
sharkbc7-Oct-09 23:30 
AnswerRe: Epub-LRFTools Pin
42774808-Oct-09 1:04
42774808-Oct-09 1:04 
GeneralRe: Epub-LRFTools Pin
sharkbc8-Oct-09 17:11
sharkbc8-Oct-09 17:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.