Results 1 to 8 of 8
Thread: Problem with Encoding
- 02-28-2011, 04:51 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Problem with Encoding
Hello, I am developing simple dictionary, I have problem with Encoding. I have "slovar.txt" saved in UTF-8:
and the following code:Java Code:Термин0 = Значение0 Термин1 = Значение1 Термин2 = Значение2 Термин3 = Значение3 Термин4 = Значение4 Термин5 = Значение5 Термин6 = Значение6 Термин7 = Значение7 Термин8 = Значение8 Термин9 = Значение9
How it occurs? How can I fix this code in orderJava Code:import java.io.*; import java.util.*; public class NewClass { public static void main(String [] args) throws UnsupportedEncodingException{ BufferedReader bf = null; String url = "slovar.txt"; Map<String, String> map = new TreeMap<String, String>(); String test = null; try{ bf = new BufferedReader(new InputStreamReader (new FileInputStream(url), "UTF-8")); String line = null; while( (line=bf.readLine())!=null ){ String phrase = line.substring(0, line.indexOf("=")); String meaning = line.substring(line.indexOf("=")+1, line.length()); test = phrase; map.put(phrase, meaning); } }catch(Exception ex){ ex.printStackTrace(); } //now test="Термин9"; String str = "Термин9"; System.out.println(map.containsKey(test));// prints TRUE System.out.println(map.containsKey(str));// prints FALSE } }
to print TRUE???Java Code:System.out.println(map.containsKey(str));// to print TRUE???
Please if anyone knows explain me
- 02-28-2011, 05:12 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
that is because you have a space at the end of your key strings !
try
orJava Code:String phrase = line.substring(0, line.indexOf("=") -1);
orJava Code:map.put(phrase.trim(), meaning.trim());
:DJava Code:String str = "Термин9 ";
- 02-28-2011, 05:58 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 16
- Rep Power
- 0
Thanks Eraaaaaaaaaaaaaaaaaa, I forgot about spaces, thanks a lot.
- 02-28-2011, 06:55 PM #4
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
hey sori but I'm having trouble with where to post my code for help so this is not a reply but anther questionimport java.util.*;
import java.io.*;
public class Assignment1
{
public static void main(String[] args)
{
System.out.println("I'm here");
Scanner readFileA =null;
Scanner readFileB =null;
String wordSearched =null;
String[] array=null;
try{
readFileA=new Scanner(new FileInputStream("FileA.in"));
readFileB=new Scanner(new FileInputStream("FileB.in"));
}
catch(FileNotFoundException Fe)
{
System.out.println("Not Found");
}
int count=0;
int position =0;
String line = null;
System.out.println("H");
int i=0;
while(readFileA.hasNextLine())
{
line = readFileA.nextLine();
if(count==0)
{
array=new String[Integer.parseInt(line)];
}
else
{
array[i]=line;
i++;
}
count++;
}
public int SeqSearch(String[]array,String wordSearched)
{
for(int j=0 ;j<array.length ;j++)
if(WorSearched.compareTo(array[j]))
return i;
return -1;
}
}
}
- 02-28-2011, 06:57 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
this is not an answer but a question I'm having trouble with this my code.
import java.util.*;
import java.io.*;
public class Assignment1
{
public static void main(String[] args)
{
System.out.println("I'm here");
Scanner readFileA =null;
Scanner readFileB =null;
String wordSearched =null;
String[] array=null;
try{
readFileA=new Scanner(new FileInputStream("FileA.in"));
readFileB=new Scanner(new FileInputStream("FileB.in"));
}
catch(FileNotFoundException Fe)
{
System.out.println("Not Found");
}
int count=0;
int position =0;
String line = null;
System.out.println("H");
int i=0;
while(readFileA.hasNextLine())
{
line = readFileA.nextLine();
if(count==0)
{
array=new String[Integer.parseInt(line)];
}
else
{
array[i]=line;
i++;
}
count++;
}
public int SeqSearch(String[]array,String wordSearched)
{
for(int j=0 ;j<array.length ;j++)
if(WorSearched.compareTo(array[j]))
return i;
return -1;
}
}
}
- 02-28-2011, 06:58 PM #6
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 02-28-2011, 07:08 PM #7
Member
- Join Date
- Feb 2011
- Posts
- 3
- Rep Power
- 0
cant find the new thread button
hey guys i cant find the new thread button and the question I wanted ask was(check code assignment1.java),I'm basically having trouble moving on,what I'msupposed to do is to read input from one two files and compare the words to find if one file has the same words as the other file and the number of lines is indicated at the start of the file and can passed as array size plzzzzzzzzzz help:(
- 02-28-2011, 07:47 PM #8
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Similar Threads
-
Internet Explorer + AJAX + UTF encoding problem
By pacinpm in forum JavaServer Faces (JSF)Replies: 0Last Post: 11-30-2010, 09:04 AM -
problem in encoding
By jaysh in forum NetBeansReplies: 0Last Post: 08-26-2010, 08:07 AM -
Problem with Base64 encoding
By Smirgu in forum Advanced JavaReplies: 1Last Post: 04-15-2010, 11:05 AM -
Encoding Problem
By GJ! in forum Advanced JavaReplies: 6Last Post: 01-12-2010, 08:09 PM -
Lucene Indexer Encoding problem
By svirid in forum LuceneReplies: 5Last Post: 02-18-2009, 09:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks