The following history is from Wikipedia.
Legend has it that soldiers of the Polish-Habsburg army, while liberating Vienna from the second Turkish siege in 1683, found a number of sacks with strange beans that they initially thought were camel feed and wanted to burn. The Polish king Jan III Sobieski granted the sacks to one of his officers named Jerzy Franciszek Kulczycki, who started the first coffee house. After some experimentation, he added some sugar and milk, and the Viennese coffee tradition was born. This achievement has been recognized in many modern Viennese coffeehouses by hanging a picture of Kulczycki in the window. Another account is that Kulczycki, having spent two years in Ottoman captivity, knew perfectly well what coffee really is and tricked his superiors into granting him the beans that were considered worthless.
The new drink was well received, and coffee houses began to pop up rapidly. In the early period, the various drinks had no names, and customers would select the mixtures from a colour-shaded chart.
The heyday of the coffee house was the turn of the nineteenth century when writers like Peter Altenberg, Alfred Polgar, Karl Kraus, Hermann Broch and Friedrich Torberg made them their preferred place of work and pleasure. Many famous artists, scientists, and politicians of the period such as Arthur Schnitzler, Stefan Zweig, Egon Schiele, Gustav Klimt, Adolf Loos, Theodor Herzl, Alfred Adler, and even Leon Trotsky were constant coffee house patrons. In Prague, Budapest, Cracow, and Lviv (Lemberg) and other cities of the Austro-Hungarian empire there were also many coffee houses according to the Viennese model.
From 1950, the period of "coffee house death" or Kaffeehaussterben began, as many famous Viennese coffee houses had to close, perhaps due to the popularity of television or the appearance of modern espresso bars. Nevertheless, many of these classic Viennese spots still exist, and tourism and a renewed interest in their history have prompted a comeback.