China and Japan had different policies to trade in the 19th century. Where the Chinese chose to close themselves in, the Japanese chose to trade with the newcomers.
In the 19th century, China was a major manufacturing superpower. The Chinese did not buy many goods from European exporters like Britain because they could make the articles themselves. However, the British soon found a lucrative way to make money in China: selling opium illegally.
However, the Chinese government did not like the import of opium into their country. A petition was sent to Queen Elizabeth to stop this trade. However, it was refused and when the Chinese closed their ports to British merchants, the British just defeated them with their superior arms. In the Treaty of Nanking, the British forced China to exclusive trading rights.
The Japanese were also self-sufficient and did not want to open up trading relations with the outside world. However, when Commodore Matthew Perry (an American sailor) arrived with American weapons and technology, the Japanese decided on exclusive trade rights for the Americans so they could acquire their technology.