High-Q nanocavities have been extensively studied recently because they are considered key elements in low-power photonic devices and integrated circuits. Here we demonstrate that ultrahigh-Q (>10(6)) nanocavities can be created by employing scanning probe lithography on a prepatterned line defect in a silicon photonic crystal. This is the first realization of ultrahigh-Q nanocavities by the postprocess modification of photonic crystals. With this method, we can form an ultrahigh-Q nanocavity with controllable cavity parameters at an arbitrary position along a line defect. Furthermore, the fabricated nanocavity achieves ultralow power all-optical bistable operation owing to its large cavity enhancement effect. This demonstration indicates the possibility of realizing photonic integrated circuits on demand, where various circuit patterns are written with a nanoprobe on a universal photonic crystal substrate.