#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2017
    Posts
    1
    Rep Power
    0

    Split a Text File?


    Hello everyone,

    I am trying to develop a Morse to English translator in Java.

    At the moment, I am trying to split the text file.

    However, I am struggling.

    Can anyone help?

    Code:
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    
    class MorsetoEnglish {
    
    	public static void main(String[] args) {
    		
    	        try{
    	        
    	        BufferedReader input = new BufferedReader(new FileReader("morse.txt"));
    	        
    	        	String[] English = {"a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "u" , "v" , "x" , "y" , "z"};
    	            String[] Code = { ".-" , "-..." , "-.-." , "-.." , "." , "..-." , "--." , "...." , ".." , ".---" , "-.-" , ".-.." , "--" , "-." , "---" , ".--." , "--.-" ,  ".-." , "..." , "-" , "..-" , "...-" , ".--" , "-..-" , "-.--" , "--.." , "|"};
    	        
    	        
    	            String line;
    				while ((line = input.readLine()) != null)
    	            {
    					
    					String[] One = morse.split(",");
    					
    	                System.out.println(line);
    	            }
    	        }
    	        catch (IOException ex)
    	        {
    	             ex.printStackTrace();
    	        }
    	    }
    	}
  2. #2
  3. Lord of the Dance
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Oct 2003
    Posts
    4,131
    Rep Power
    2010
    Can you explain what you try to do?
    You try to split on a variable called morse, I think you mean line.
    One is overwritten for each line, making it only to save the value from last iteration.
    If you want to use a variable outside the loop, it should also be declared outside.

IMN logo majestic logo threadwatch logo seochat tools logo