-1

I'm looking to rewrite my whole .txt file of numbers e.g. 302340372048725280 to 3 0 2 3 4 0 3 7 2 0 4 8 7 2 5 2 8 0. How may I do this?

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class IntSeparator {

    public static void main(String[] args) throws IOException {
        Scanner scanner;
        try {
            scanner = new Scanner(new File("src/extremePuzzles.txt"));

            PrintWriter spacer = new PrintWriter(new FileWriter("src/extremePuzzles.txt", true));

            while (scanner.hasNext()) {
                String puzzle = scanner.next();
                System.out.println(puzzle);

                String splitted = puzzle.replace("", " ").trim();
                System.out.println(splitted);

                spacer.print(splitted);
            }

        } catch (FileNotFoundException e) {
            System.out.println("file not found!");
        }
    }
}
jmoerdyk
  • 5,544
  • 7
  • 38
  • 49
Tai
  • 53
  • 1
  • 7

1 Answers1

0

simple string processing may work as below

public class Str{

    public static void main(String args[]){
    String str = "302340372048725280";

    String temp = "";
    int i=0;
    int len = str.length();
    while(len>0){
        temp+=str.charAt(i);
        i++;
        len--;
        temp+=" ";
    }

   System.out.println(temp);

   }
}

You can use this code as per your need!

01000001
  • 833
  • 3
  • 8
  • 21