Results 1 to 4 of 4
  1. #1
    Mobius-1 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default How do you Use Backslash as a Delimiter?

    I'm attempting to read a filepath as a string and delimit it based off of it's '\' characters.
    For example, C:\Users\Desktop would be read as
    C:
    Users
    Desktop

    The code is as follows:

    Java Code:
    import java.io.File;
    import java.util.Scanner;
    import javax.swing.JFileChooser;
    
    public class AppsPageCreator_v1_0 {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String[] fileInfo = openSequence("Choose app");
    		System.out.println(fileInfo[0] + " " + fileInfo[1]);
    		Scanner input = new Scanner(fileInfo[1]).useDelimiter("\\");
    		while(input.hasNext())
    		{
    			System.out.println(input.next());
    		}
    	}
    	public static String[] openSequence(String label)
    	{
    		JFileChooser open = new JFileChooser();
    		int checkIfOpen = open.showDialog(null, label);
    		String [] returnArray = new String [2];
    		File openedFile = open.getSelectedFile();
    		if(checkIfOpen==0)
    		{
    			returnArray[0] = "Success";
    			returnArray[1] = openedFile.getAbsolutePath();
    		}
    		else
    			returnArray[0] = "Canceled";
    		return returnArray;
    	}
    }
    I get an error on the line containing
    Scanner input = new Scanner(fileInfo[1]).useDelimiter("\\");

    Something tells me it's because I'm trying to use \\ as a delimiter.
    All help appreciated, thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

  3. #3
    Mobius-1 is offline Member
    Join Date
    Oct 2009
    Posts
    2
    Rep Power
    0

    Default

    Thank you, problem solved.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

Similar Threads

  1. Backslash, File directories, and streams
    By rp181 in forum Advanced Java
    Replies: 4
    Last Post: 10-15-2009, 09:54 AM
  2. Delimiter question
    By Kangaroo128 in forum New To Java
    Replies: 10
    Last Post: 09-09-2009, 09:28 AM
  3. using Delimiter with metacharacters
    By wntdaliv in forum New To Java
    Replies: 10
    Last Post: 12-02-2008, 06:42 AM
  4. delimiter
    By satin in forum New To Java
    Replies: 2
    Last Post: 11-17-2008, 10:50 PM
  5. How to handle \ (backslash) in regular expressions
    By federal102 in forum New To Java
    Replies: 1
    Last Post: 11-02-2008, 01:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •