-5

Learning file I/O in java, but cant seem to get java to recognize this format in a text document :

    A=1
    B=2
    .
    .
    .
    .
    Z=26

What i want is for the letters A through Z to be equal to the int counterpart, I've been able to do this in C# using this code:

        var dic = File.ReadAllLines(AplhabetFile)
                  .Select(l => l.Split(new[] { '=' }))
                  .ToDictionary(s => s[0].Trim(), s => s[1].Trim());

but i can't seem to find its exact java equivalent anywhere. Any Ideas ?

Commongrate
  • 123
  • 12
  • 3
    "*but i can't seem to find its exact java equivalent anywhere*", really ? [Reading a plain text file in Java](http://stackoverflow.com/questions/4716503/reading-a-plain-text-file-in-java) and [How to split a string in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java). Where did *you* look ? – dumbPotato21 May 18 '17 at 05:42

1 Answers1

2

You can do the same with Streams:

Map<String, String> dic = Files.lines(Paths.get(AlphabetFile))
        .map(l -> l.split("="))
        .collect(Collectors.toMap(s -> s[0].trim(), s -> s[1].trim()));
shmosel
  • 42,915
  • 5
  • 56
  • 120