diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java index ba8779fd..582136e1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Sparrow.java @@ -101,9 +101,12 @@ public class Sparrow implements WalletImport, WalletExport { java.nio.file.Files.copy(inputStream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); PersistenceType persistenceType = Storage.detectPersistenceType(tempFile); persistenceType = (persistenceType == null ? PersistenceType.JSON : persistenceType); - File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension()); - tempFile.renameTo(tempTypedFile); - tempFile = tempTypedFile; + if(persistenceType != PersistenceType.JSON || !isEncrypted(tempFile)) { + File tempTypedFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + persistenceType.getExtension()); + tempFile.renameTo(tempTypedFile); + tempFile = tempTypedFile; + } + storage = new Storage(persistenceType, tempFile); if(!isEncrypted(tempFile)) { wallet = storage.loadUnencryptedWallet().getWallet(); diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java index a98ca266..12c4f89e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Storage.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Storage.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermissions; @@ -373,7 +374,7 @@ public class Storage { } public static PersistenceType detectPersistenceType(File walletFile) { - try(Reader reader = new FileReader(walletFile)) { + try(Reader reader = new FileReader(walletFile, StandardCharsets.UTF_8)) { int firstChar = reader.read(); if(firstChar == 'U' || firstChar == '{') {