小编Avi*_*ash的帖子

csv解析器读取标头

我正在研究一个csv解析器,我想分别读取头文件和其余的csv文件.这是我读取csv的代码.

当前代码读取csv文件中的所有内容,但我需要单独读取标头.请帮我解决这个问题.

public class csv {

private void csvRead(File file)
{
    try
    {
    BufferedReader br = new BufferedReader( new FileReader(file));
    String strLine = "";
    StringTokenizer st = null;
    File cfile=new File("csv.txt");
    BufferedWriter writer = new BufferedWriter(new FileWriter(cfile));
    int tokenNumber = 0;

    while( (strLine = br.readLine()) != null)
    {
            st = new StringTokenizer(strLine, ",");
            while(st.hasMoreTokens())
            {

                    tokenNumber++;
                    writer.write(tokenNumber+"  "+ st.nextToken());
                    writer.newLine();
            }


            tokenNumber = 0;
            writer.flush();
    }
}

    catch(Exception e)
    {
        e.getMessage();
    }
}
Run Code Online (Sandbox Code Playgroud)

java csv parsing

11
推荐指数
3
解决办法
3万
查看次数

在RSA加密中需要帮助(doFinal)

我正在尝试使用RSA算法加密和解密字符串.这里的加密工作正常,但问题在于解密.代码在DECRYPT方法中到达doFinal时终止.我输错了还是公钥和私钥有问题?请给我这个建议.感谢你.

public class rsa 
{   
 private KeyPair keypair;       

 public rsa() throws NoSuchAlgorithmException, NoSuchProviderException 
    {
        KeyPairGenerator keygenerator = KeyPairGenerator.getInstance("RSA");
        SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
        keygenerator.initialize(1024, random);
        keypair = keygenerator.generateKeyPair();
    }
public String ENCRYPT(String Algorithm, String Data ) throws Exception
{   
    String alg = Algorithm;
    String data=Data;
    byte[] encrypted=new byte[2048];
    if(alg.equals("RSA"))
    {   

        PublicKey publicKey = keypair.getPublic();
        Cipher cipher;
        cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
         encrypted = cipher.doFinal(data.getBytes());
        System.out.println("Encrypted String[RSA] -> " + encrypted);
    }
    return encrypted.toString();
}
public String DECRYPT(String Algorithm, String Data …
Run Code Online (Sandbox Code Playgroud)

java encryption cryptography rsa public-key-encryption

4
推荐指数
1
解决办法
8404
查看次数