Results 1 to 4 of 4
- 12-13-2009, 11:06 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
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:
I get an error on the line containingJava 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; } }
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.
-
- 12-13-2009, 11:33 PM #3
Member
- Join Date
- Oct 2009
- Posts
- 2
- Rep Power
- 0
Thank you, problem solved.
-
Similar Threads
-
Backslash, File directories, and streams
By rp181 in forum Advanced JavaReplies: 4Last Post: 10-15-2009, 09:54 AM -
Delimiter question
By Kangaroo128 in forum New To JavaReplies: 10Last Post: 09-09-2009, 09:28 AM -
using Delimiter with metacharacters
By wntdaliv in forum New To JavaReplies: 10Last Post: 12-02-2008, 06:42 AM -
delimiter
By satin in forum New To JavaReplies: 2Last Post: 11-17-2008, 10:50 PM -
How to handle \ (backslash) in regular expressions
By federal102 in forum New To JavaReplies: 1Last Post: 11-02-2008, 01:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks