<p>Bitcoinj doesn't read Bitcoin Core wallet.dat files. You need to start a
fresh wallet and move coins into it using a standard Bitcoin transaction</p>

CC BY-SA 4.0
2018-05-27T17:01:59.590Z
2018-05-27T17:01:59.590Z
Zombie
<p>So I want to load a wallet and get its balance also sending some funds with the corresponding wallet, here is my code</p>

<pre><code>public class DumpWallet {
public static void main(String[] args) throws Exception {


    Wallet wallet = Wallet.loadFromFile(new File("wallet.dat"));
    System.out.println(wallet.toString());
}
}
</code></pre>

<p>Why does it throw these followings error (I am using wallet.dat that created automatically on <code>C:\Users\&lt;username&gt;\AppData\Roaming\Bitcoin\testnet3</code></p>

<pre><code>Exception in thread "main" org.bitcoinj.wallet.UnreadableWalletException: Could not parse input stream to protobuf
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:427)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:399)
at org.bitcoinj.wallet.Wallet.loadFromFileStream(Wallet.java:1581)
at org.bitcoinj.wallet.Wallet.loadFromFile(Wallet.java:1487)
at org.bitcoinj.examples.DumpWallet.main(DumpWallet.java:33)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
    at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
    at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
    at org.bitcoinj.wallet.Protos$Wallet.&lt;init&gt;(Protos.java:14789)
    at org.bitcoinj.wallet.Protos$Wallet.&lt;init&gt;(Protos.java:14778)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:14956)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:1)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:89)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:95)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
    at org.bitcoinj.wallet.Protos$Wallet.parseFrom(Protos.java:15822)
    at org.bitcoinj.wallet.WalletProtobufSerializer.parseToProto(WalletProtobufSerializer.java:606)
    at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:420)
    ... 4 more
</code></pre>

<bitcoin-core><bitcoind><client><bitcoinj>
Bitcoinj unable to load wallet
thegexploit
# Bitcoinj unable to load wallet

(Asked by: username_0 on 2018-03-08)

So I want to load a wallet and get its balance also sending some funds with the corresponding wallet, here is my code
public class DumpWallet {
public static void main(String[] args) throws Exception {


    Wallet wallet = Wallet.loadFromFile(new File("wallet.dat"));
    System.out.println(wallet.toString());
}
}

Why does it throw these followings error (I am using wallet.dat that created automatically on C:\Users\\AppData\Roaming\Bitcoin\testnet3
Exception in thread "main" org.bitcoinj.wallet.UnreadableWalletException: Could not parse input stream to protobuf
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:427)
at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:399)
at org.bitcoinj.wallet.Wallet.loadFromFileStream(Wallet.java:1581)
at org.bitcoinj.wallet.Wallet.loadFromFile(Wallet.java:1487)
at org.bitcoinj.examples.DumpWallet.main(DumpWallet.java:33)
Caused by: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
    at com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:89)
    at com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:158)
    at org.bitcoinj.wallet.Protos$Wallet.(Protos.java:14789)
    at org.bitcoinj.wallet.Protos$Wallet.(Protos.java:14778)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:14956)
    at org.bitcoinj.wallet.Protos$Wallet$1.parsePartialFrom(Protos.java:1)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:89)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:95)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:49)
    at org.bitcoinj.wallet.Protos$Wallet.parseFrom(Protos.java:15822)
    at org.bitcoinj.wallet.WalletProtobufSerializer.parseToProto(WalletProtobufSerializer.java:606)
    at org.bitcoinj.wallet.WalletProtobufSerializer.readWallet(WalletProtobufSerializer.java:420)
    ... 4 more

**Tags:** bitcoin-core, bitcoind, client, bitcoinj


---

## 1 answers

### Answer by username_1 on 2018-05-27. Score: 1

Bitcoinj doesn't read Bitcoin Core wallet.dat files. You need to start a
fresh wallet and move coins into it using a standard Bitcoin transaction


---

